Closed
Description
This fails on the playground, and I believe it also fails on [email protected]
TypeScript Version: [email protected]
Search Terms: unknown intersection failure types narrow
Code
interface TypeA {
Name: "TypeA";
Value1: "Cool stuff!";
}
interface TypeB {
Name: "TypeB";
Value2: 0;
}
type Type = TypeA | TypeB;
declare function isType(x: unknown): x is Type;
function WorksProperly(data: Type) {
if (data.Name === "TypeA") {
// data: TypeA
const value1 = data.Value1;
}
}
function DoesNotWork(data: unknown) {
if (isType(data)) {
if (data.Name === "TypeA") {
// data: Type
// data should be TypeA
const value1 = data.Value1; // type error!
}
}
}
Expected behavior: in DoesNotWork
, data
should be TypeA after we can guarentee it is named "TypeA"
Actual behavior: data
is still only a Type
Related Issues: I looked through several pages of issues and did not find anything similar.