Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear TypeError thrown when field is of type Function #135

Closed
jakefurler opened this issue Jul 3, 2017 · 2 comments
Closed

Unclear TypeError thrown when field is of type Function #135

jakefurler opened this issue Jul 3, 2017 · 2 comments

Comments

@jakefurler
Copy link

If I define a schema with a field of type Function, an unclear error is thrown.

/.../schemas/node_modules/typescript-json-schema/typescript-json-schema.js:421
            var indexSignatures = clazz.members.filter(function (x) { return x.kind === ts.SyntaxKind.IndexSignature; });
                                               ^

TypeError: Cannot read property 'filter' of undefined

This only occurs for recent versions of the library, introduced in #117. Without that change, I get a definition produced like this:

"Function": {
            "additionalProperties": false,
            "description": "Creates a new function.",
            "properties": {
                "__@hasInstance": {
                    "additionalProperties": false,
                    "description": "Determines whether the given value inherits from this function if this function was used\nas a constructor function.\n\nA constructor function can control which objects are recognized as its instances by\n'instanceof' by overriding this method.",
                    "type": "object"
                },
                "apply": {
                    "additionalProperties": false,
                    "description": "Calls the function, substituting the specified object for the this value of the function, and the specified array for the arguments of the function.",
                    "type": "object"
                },
                "arguments": {
                },
                "bind": {
                    "additionalProperties": false,
                    "description": "For a given function, creates a bound function that has the same body as the original function.\nThe this object of the bound function is associated with the specified object, and has the specified initial parameters.",
                    "type": "object"
                },
                "call": {
                    "additionalProperties": false,
                    "description": "Calls a method of an object, substituting another object for the current object.",
                    "type": "object"
                },
                "caller": {
                    "$ref": "#/definitions/Function"
                },
                "length": {
                    "type": "number"
                },
                "name": {
                    "description": "Returns the name of the function. Function names are read-only and can not be changed.",
                    "type": "string"
                },
                "prototype": {
                },
                "toString": {
                    "additionalProperties": false,
                    "description": "Returns a string representation of a function.",
                    "type": "object"
                }
            },
            "required": [
                "__@hasInstance",
                "apply",
                "arguments",
                "bind",
                "call",
                "caller",
                "length",
                "name",
                "prototype",
                "toString"
            ],
            "type": "object"
        },

Not sure if Functions are really supported, see #110. But the message should at least be clearer.

@domoritz
Copy link
Collaborator

domoritz commented Jul 3, 2017

Functions are generally not supported but Function is treated as an object. Can you try to fix the issu that you are seeing.

CC @otgerrogla

@jakefurler
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants