Skip to content

inference problem with constraints involving conditionals and generics  #29662

Description

the following is seen in typescript@3.4.0-dev.20190131:

declarefunctiononlyNullablePlease<Textends(nullextendsT ? any : never)>(value: T): void;declarevarz: string|null;onlyNullablePlease(z);// works as expecteddeclarevary: string;onlyNullablePlease(y);// error as expectedfunctionf<T>(t: T){varx: T|null=Math.random()>0.5 ? null : t;onlyNullablePlease(x);// should work, unexpected error:/*Argument of type 'T | null' is not assignable to parameter of type 'null extends T | null ? any : never'. Type 'null' is not assignable to type 'null extends T | null ? any : never'.ts(2345) */}

Metadata

Metadata

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions