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

Type definition error (TypeScript) when enable strictNullChecks #592

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

Type definition error (TypeScript) when enable strictNullChecks #592

k8w opened this issue Dec 29, 2016 · 2 comments

Comments

@k8w
Copy link

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
Copy link
Member

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 as completed Dec 30, 2016
@k8w
Copy link
Author

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
Projects
None yet
Development

No branches or pull requests

2 participants