You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
declareclassExampleClass{prop: number;}typeTakesExample<TextendsExampleClass>=T;typeTest<TextendstypeofExampleClass|(new()=>object)>=TextendstypeofExampleClass
? TakesExample<InstanceType<T>>// ^ Type 'InstanceType<T>' does not satisfy the constraint 'ExampleClass'.// Type 'unknown' is not assignable to type 'ExampleClass'.// Type 'object | ExampleClass' is not assignable to type 'ExampleClass'.// Property 'prop' is missing in type '{}' but required in type 'ExampleClass'.
: never;
π Actual behavior
This errors because it appears to lose the context that T is typeof ExampleClass when ran through InstanceType. I find this especially odd because if you make a TakesExampleClass<T> it'll succeed.
π Expected behavior
No error.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
LukeAbby
changed the title
Incorrect Narrowing of a Union of Constructors
Incorrect Apparent Type of a Union of Constructors
Dec 22, 2024
π Search Terms
union of constructors, InstanceType, narrowing
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=4.9.5#code/CYUwxgNghgTiAEkoGdnwKIA8oFsAOEIAwtKvAN4CwAUPHfHjAPZ4Bc8AdgK44BGIMANw0AvjRoAXAJ54EAFSgBrEMiy4CIADxz4ITBJAdgaNfkIkUyAHzwAvPDnDqkmfJUTtu-YePxpspgAzDGwzYlI0AB94AAoOEAB3WIBKOxsmXgArcAlkm3sdPQMjNH8QIJD1cwiaengAfgclFVMNTQBJDmQJKA4wEDlXbSsrWvoAenG66bqAPQdXeAByTu7e-sHZYaX4YCYVTiYJeGQoCQBLZECpPwALBDAmLokYKHOOY6XW6sslgDoxnRJjMQXVNggllwOIoOEwEhwdpdDsdLOcAOYcKC8Qh+Jh+RZfUIaCyof6A+DA0FUhayZYZbJgY7Rb7hX7wJGwlGodGY7EICR4srLFkk5Bk2gTKbU6kABWYshg0mWjBYiLQOEuyHeaPZHHxtKW5BEO14XGOcAAjlxznBgLr9RCRRFxXV2PEAG4CQRAA
π» Code
π Actual behavior
This errors because it appears to lose the context that
T
istypeof ExampleClass
when ran throughInstanceType
. I find this especially odd because if you make aTakesExampleClass<T>
it'll succeed.π Expected behavior
No error.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: