Skip to content

Type definition error (TypeScript) when enable strictNullChecks #592

@k8w

Description

@k8w

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;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions