-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Generic parameter is considered object #27093
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
TypeScript Version: 3.1.0-dev.201xxxxx
Search Terms: generics, typeof, object, never
Code
function f<TData>(data: TData): boolean {
if (typeof data === "object") return true;
return data;
}
let x: boolean = f(1);Expected behavior:
Code should not compile - function actually returns boolean | TData, but states only boolean
Actual behavior:
Code compiles without errors. After the if statement, data is considered never
Related Issues:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue