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

Type definition error (TypeScript) when enable strictNullChecks #592

Closed
k8w opened this Issue Dec 29, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@k8w

k8w commented Dec 29, 2016

tsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "sourceMap": true,
        "moduleResolution": "node",
        "strictNullChecks": true
    }
}

when compiled, it will error:

ERROR in E:\Codes\ChartMaker\frontend\node_modules\protobufjs\types\protobuf.js.d.ts
(1284,11): error TS2417: Class static side 'typeof Root' incorrectly extends base class static side 'typeof Namespace'.
Types of property 'fromJSON' are incompatible.
Type '(json: any, root?: Root | undefined) => Root' is not assignable to type '(name: string, json: Object) => Namespace'.
Types of parameters 'root' and 'json' are incompatible.
Type 'Object' is not assignable to type 'Root | undefined'.
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Type 'Object' is not assignable to type 'Root'.
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Property 'deferred' is missing in type 'Object'.
webpack: bundle is now VALID.

Solution

protobuf.js.d.ts, Line 1313 change to :

static fromJSON(json: any, root: Root): Root;

or

protobuf.js.d.ts, Line 754 change to :

static fromJSON(name: string, json?: Object): Namespace;

dcodeIO added a commit that referenced this issue Dec 29, 2016

@dcodeIO

This comment has been minimized.

Owner

dcodeIO commented Dec 29, 2016

I am not exactly sure if this fixes the issue, so please let me know.

I actually believe that not being able to override static methods like that with TypeScript is wrong. There should be a way to force it because it sometimes makes sense.

@k8w k8w closed this Dec 30, 2016

@k8w

This comment has been minimized.

k8w commented Dec 30, 2016

I actually believe that not being able to override static methods like that with TypeScript is wrong.

Agree, and finally I solve this by add a declaration in my custom.d.ts:

declare module 'protobufjs';

I always use static-module js file, so above makes protobufjs as any to ignore this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment