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);
}
}
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.
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[] = []; .
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With