YoYoGames / GameMaker-Bugs

Public tracking for GameMaker bugs
13 stars 5 forks source link

Type definitions, at least in Feather & JSDoc #5826

Open Furkan-Karabudak opened 3 weeks ago

Furkan-Karabudak commented 3 weeks ago

Is your feature request related to a problem?

It'd be great if we could manually assign the types we want in GM like myVariable : string = "hello"; This is probably a much bigger job to do behind the scenes (maybe you do in GMRT idk xd). So at least something can be done specifically for JSDocs and Feather.

While writing libraries, it is very bad that we can only write string as the type of a parameter or what is returned, or simply struct without being able to write about it's content etc. Maybe my function only takes strings with certain content, not all kinds of strings. Maybe the user (or me, I sometimes forget too) feels the need to check the content of the struct returned by the function each time.

You can bring the JSDoc tags @type, @typedef and @property. This way we can define our own types and assign them to variables, function parameters, return types etc. at least in Feather to show.

Describe the solution you'd like

This is just an example, I've written a function named code_file() which is simply a func returns more advanced _GMFILE_ info. I just want to be able to do this:

/** @typedef  {Struct} CodeFileInfo
*   @property {String} name    The file name without the prefix `gml_xxx`
*   @property {String} fullname    The file name including the prefix `gml_xxx`
*   @property {Type.Script, Type.Object, Type.Room} type    The code file type (Assume I also defined these before.)
*/

/** @desc Returns the current code file info as a struct.
*   @return {CodeFileInfo}    Current code file info
*/
function code_file() {
    // some code
    return {
        name : _name,
        fullname : _GMFILE_,
        type : _type,
    };
}

This way people can see the content of the struct returned directly in Feather and do not have to go look at the func declaration. This is just one use case. This can be used in many places and is useful I think.

Describe alternatives you've considered

If you don't add the tags @typedef, @type or @property, you can also simply allow this:

/** @desc Returns the current code file info as a struct.
*   @return {{name: String, fullname: String, type: String}}    Current code file info
. . .

Additional context

For example, it might look something like this in Feather:

FeatherConcept