Skip to content

handle null does not effect for string #2223

@HerrCai0907

Description

@HerrCai0907
let a = 1;

function foo(): string | null {
  return a > 10 ? null : "";
}

export class B {
  test(): void {
    let t: string | null = foo();
    if (t != null) {
      let v: string = t;  // ERROR TS2322: Type '~lib/string/String | null' is not assignable to type '~lib/string/String'.
    }
  }
}

export function test(): void {
  let t: string | null = foo();
  if (t != null) {
    let v: string = t;   // ERROR TS2322: Type '~lib/string/String | null' is not assignable to type '~lib/string/String'.
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions