Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebStorm: Argument type this is not assignable to parameter type ObjectConstructor

Tags:

When I use the following constructor in TypeScript, I get the error Argument type this is not assignable to parameter type ObjectConstructor. But CLI is not showing the error. The code looks OK to me (syntax). Is this a false error?

export class Store{
  oid: string;
  storeNumber: string;
  address: string;

  public constructor(init?: Partial<Store>) {
    Object.assign(this, init);
  }
}
like image 994
jprism Avatar asked Jan 15 '19 16:01

jprism


People also ask

Is not assignable to parameter type?

The error "Argument of type 'string | null' is not assignable to parameter of type string" occurs when a possibly null value is passed to a function that expects a string . To solve the error, use a type guard to verify the value is a string before passing it to the function.

Is not assignable to parameter of type never?

The error "Argument of type is not assignable to parameter of type 'never'" occurs when we declare an empty array without explicitly typing it and attempt to add elements to it. To solve the error, explicitly type the empty array, e.g. const arr: string[] = []; .

Is not assignable to type TypeScript?

The "Type 'string' is not assignable to type" TypeScript error occurs when we try to assign a value of type string to something that expects a different type, e.g. a more specific string literal type or an enum. To solve the error use a const or a type assertion.


1 Answers

This has been logged as a WebStorm bug. (Thank you, @lena).

Until a fix is issued, one could supress the inspection by placing the following comment above the line containing the false positive:

// noinspection TypeScriptValidateTypes
like image 160
tao Avatar answered Jan 04 '23 16:01

tao