Skip to content

inference problem with constraints involving conditionals and generics  #29662

Closed
@zpdDG4gta8XKpMCd

Description

@zpdDG4gta8XKpMCd

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

declare function onlyNullablePlease<T extends (null extends T ? any : never)>(value: T): void;

declare var z: string | null;
onlyNullablePlease(z); // works as expected

declare var y: string;
onlyNullablePlease(y); // error as expected

function f<T>(t: T) {
    var x: 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

Assignees

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