-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
Not a DefectThis behavior is one of several equally-correct optionsThis behavior is one of several equally-correct options
Description
π Search Terms
assetion union type
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ
β― Playground Link
π» Code
type StringOrNumber = string | number;
type StringOrBoolean = string | boolean;
declare let value1: StringOrNumber ;
declare let value2: StringOrBoolean ;
// value1 = value2;
let converted = value1 as StringOrBoolean;
StringOrNumber
and StringOrBoolean
do not have a subtype-supertype relationship, i.e., they can not be assigned to each other; how can they be asserted to each other then?
The LLM said this is legal because they overlap somehow, however
type A = { a: string; b: number };
type B = { a: string; c: boolean };
let a: A = { a: "test", b: 123 };
let b = a as B;
Such code is treated as legal by LLM, but it does not actually which is expected
How come value1 as StringOrBoolean
is legal, is this a bug?
π Actual behavior
type StringOrNumber = string | number;
type StringOrBoolean = string | boolean;
declare let value1: StringOrNumber ;
declare let value2: StringOrBoolean ;
// value1 = value2;
let converted = value1 as StringOrBoolean;
Do not throw an error
π Expected behavior
It should throw an error
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
Not a DefectThis behavior is one of several equally-correct optionsThis behavior is one of several equally-correct options