Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Generic cannot be narrowed to satisfy NonNullable #48691

Closed
Labels
DuplicateAn existing issue was already createdFix AvailableA PR has been opened for this issue
@longzheng

Description

@longzheng

Bug Report

🔎 Search Terms

  • generic can't be narrowed
  • narrow nonnullable generic

🕗 Version & Regression Information

  • This is the behavior in every version I tried from 4.6.2 to 4.0.5 and nightly v4.7.0-dev.20220408

⏯ Playground Link

Playground link with relevant code

💻 Code

functiontest<Textendsstring|null>(input:T):NonNullable<T>{if(!input){// this should narrow `input` to `T extends string`thrownewError();}returninput;// type error}

🙁 Actual behavior

Type error

Type 'T' is not assignable to type 'NonNullable<T>'.  Type 'string | null' is not assignable to type 'NonNullable<T>'.    Type 'null' is not assignable to type 'NonNullable<T>'.

🙂 Expected behavior

TypeScript should know I've narrowed the generic type to satisfied theNonNullable type.

I came across#43183 which I was expecting to also address this scenario.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdFix AvailableA PR has been opened for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp