Home > Software engineering >  Type 'null' is not assignable to type 'number'
Type 'null' is not assignable to type 'number'

Time:11-03

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?

CodePudding user response:

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

CodePudding user response:

Try changing the type of userId to

userID?: number;

or to

userID: null | number;

in your service

  • Related