Type 'null' is not assignable to type 'number'

Mike_123

I have UserID: number in my user.model.ts file and i have function to reset my form in user.component.ts. `

resetForm(form?: NgForm) {
    if(form!=null)
    form.resetForm();
    this.service.formData = {
      UserID : null,
      UserName: '',
      Password: '',
      confirmPass: '',
      FirstName: '',
      lastName: '',
      email: '',
      UserRole: ''
    }
  }

` I got error in UserID : null, Type null is not assignable to type 'number' .How to fix this issue?

Ivan Tarskich

if you don't want to hustle with such errors u can set "strictNullChecks": false, in the compilerOptions in your tsconfig.json

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Typescript: Type 'number | null' is not assignable to type 'number'

Type 'undefined' is not assignable to type '(number | null)[]'

Type 'string | number | null | undefined' is not assignable to type 'null'

Type number[][] is not assignable to type number[]

Angular - Type 'null' is not assignable to type 'number' in Angular reducer

Argument type 'string | null' not assignable to parameter type 'string | number | boolean'

Type 'number' is not assignable to type 'ReadonlyArray<{}>'

Type number is not assignable to type string

Type 'number' is not assignable to type 'string'

Type 'string' is not assignable to type 'number'

Type 'number' is not assignable to type 'TeardownLogic'

Type 'number' is not assignable to type 'never'

Type 'null' is not assignable to type 'XXX'

Type 'null' is not assignable to type 'T'

Type 'null' is not assignable to type 'ValidationErrors'

TypeScript - Type 'number | undefined' is not assignable to type 'number'

Type 'Promise<number>' is not assignable to type 'number'

Type 'number' is not assignable to type '[string | number, string]'

Type 'number | undefined' is not assignable to type 'number'

Type 'null' is not assignable to type '() => void | null'

Argument of type 'string | null' is not assignable to parameter of type 'ValueFn<SVGPathElement, Datum[], string | number | boolean | null>'

Typescript error:Type 'number' is not assignable to type 'never'

Generic function Type 'number' is not assignable to type 'U'

Argument of type 'number' is not assignable to parameter of type 'Date'

Type 'number' is not assignable to type 'Date' - Typescript not compiling

argument of type 'number' is not assignable to a parameter of type 'string'

Type 'string | number' is not assignable to type 'never'

Typescript Type 'number' is not assignable │ to type 'string'

Argument of type 'number' is not assignable to parameter of type 'string'