如何在 Angular 7 打字稿中使用 isNaN 和 charAt?

How to use isNaN and charAt in in Angular 7 typescript?

我无法使用 charAt(index)isNaN()。它说:

[ts] Cannot find name 'isNaN'.

fuctiontocheckfirstchar(control: AbstractControl) {
  const val: string = control.value;

  if (!isNaN(val.charAt(0))) {
    return null;
  } else {
    return { 'pass': true };
  }
}

使用 Number.isNaN() 而不是 isNaN()

anf for val.charAt() 确保

val is string type.