Bug Report
π Search Terms
regression conditional type inside function behaves difference
π Version & Regression Information
- This changed between versions 4.2.3 and 4.3.5
β― Playground Link
Playground link
π» Code
{
type A = Record<string, number>
type B = Record<'a' | 'b', number>
const x: A extends B ? true : false = false; // ok
}
function test() {
type A = Record<string, number>
type B = Record<'a' | 'b', number>
const x: A extends B ? true : false = false; // error
}
π Actual behavior
The conditional type resolves differently in global vs local scope.
π Expected behavior
Both should resolve the same way, preferably false in both cases.
Additional Details
This seems to have something to do with the way typescript compares aliases, wrapping one of the Record types in Omit<Record<...>, never> causes the comparison to behave normally
Playground Link
function test() {
type A = Record<string, number>
type B = Record<'a' | 'b', number>
const x: A extends B ? true : false = false; // error
}
function test2() {
type A = Omit<Record<string, number>, never>
type B = Record<'a' | 'b', number>
const x: A extends B ? true : false = false; // ok
}
function test3() {
type A = Record<string, number>;
type B = Omit<Record<'a' | 'b', number>, never>
const x: A extends B ? true : false = false; // ok
}
function test4() {
type A = Omit<Record<string, number>, never>;
type B = Omit<Record<'a' | 'b', number>, never>
const x: A extends B ? true : false = false; // error
}
Bug Report
π Search Terms
regression conditional type inside function behaves difference
π Version & Regression Information
β― Playground Link
Playground link
π» Code
π Actual behavior
The conditional type resolves differently in global vs local scope.
π Expected behavior
Both should resolve the same way, preferably
falsein both cases.Additional Details
This seems to have something to do with the way typescript compares aliases, wrapping one of the
Recordtypes inOmit<Record<...>, never>causes the comparison to behave normallyPlayground Link