Open
Description
openedon Jul 10, 2022
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
π» 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
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment