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

error TS2345 #37

Open
tfsjohan opened this issue Jan 14, 2018 · 4 comments
Open

error TS2345 #37

tfsjohan opened this issue Jan 14, 2018 · 4 comments

Comments

@tfsjohan
Copy link

I get this error when running code using the deserialize method. Why?

(133,48): error TS2345: Argument of type '(new () => {}) | undefined' is not assignable to parameter of type 'new () => {}'.
Type 'undefined' is not assignable to type 'new () => {}'.

@oalkabouss
Copy link

oalkabouss commented Jan 16, 2018

try this. using<any>before the Class type
deserialize(<any>myType,jsonObject)

@NINI1988
Copy link

NINI1988 commented May 4, 2018

I got the same error, also when using <any>.
I use the "strictNullChecks": true in tsconfig.json.

@ali-habibzadeh
Copy link

It's definitely the strictNullChecks: true that breaks it

@coddo
Copy link

coddo commented Jun 27, 2018

I'm having the same problem caused by strictNullChecks: true when building Vue app using vue-cli.
I get the following error stack when running the command vue-cli-service serve or vue-cli-service build:

133:48 Argument of type '(new () => {}) | undefined' is not assignable to parameter of type 'new () => {}'.
Type 'undefined' is not assignable to type 'new () => {}'.
131 |             if (innerJson && isArrayOrArrayClass(innerJson)) {
    132 |                 return innerJson.map(
  > 133 |                     (item: any) => deserialize(metadata.clazz, item)
        |                                                ^
    134 |                 );
    135 |             }
    136 |             return;

163:9 Type 'undefined' is not assignable to type 'T'.
if (hasAnyNullOrUndefined(Clazz, json)) {
  > 163 |         return void 0;
        |         ^
    164 |     }

170:9 Type 'undefined' is not assignable to type 'T'.
if (!isTargetType(json, 'object')) {
  > 170 |         return void 0;
        |         ^
    171 |     }

All the errors result from index.ts inside the npm package. Only happens when I actually try to import JsonProperty, serialize or deserialize.

I have configured tslint to exclude node_modules folder, but for some reason it parses just this package, so it might be some bug in TS also?

I can also confirm that setting strictNullChecks: false solves this problem, but it's definitely not an preferred workaround to use on the long-term.

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

5 participants