Bug Report
π Search Terms
- generics
- branded
- intrinsic type
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about generics
β― Playground Link
Playground link with relevant code
π» Code
/////////////////////////////////////////////////////////////////////////////////////////////// TypestypeBrandedNumber=number&{__branded: true}typeOperationIO<Textendsnumber>=TextendsBrandedNumber
? T
: number;/////////////////////////////////////////////////////////////////////////////////////////////// Functionfunctionsub<Textendsnumber>(a: OperationIO<T>,): (b: OperationIO<T>)=>OperationIO<T>{return(b)=>(b-a)asany;}/////////////////////////////////////////////////////////////////////////////////////////////// Tests// Make sure non-branded numbers work.consttestNumbers=sub(2)(3);// Make sure branded numbers work.functiontestWithoutGenerics(a: BrandedNumber,b: BrandedNumber){returnsub(a)(b);}// Subtypes of branded numbers should work too.functiontestWithGenerics<TextendsBrandedNumber>(a: T,b: T){returnsub(a)(b);// <-- Why is this not allowed?}// Has correct typing dispite above error.consttestResultWithGenerics=testWithGenerics(2asBrandedNumber&{__foo: 1},3asBrandedNumber&{__foo: 1});π Actual behavior
TypeScript reports a type error on line 35.
π Expected behavior
No error should be reported because as far I can tell, this line should be valid. Additionally, TypeScript can successfully deduce the type on line 39.
Bug Report
π Search Terms
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
TypeScript reports a type error on line 35.
π Expected behavior
No error should be reported because as far I can tell, this line should be valid. Additionally, TypeScript can successfully deduce the type on line 39.