-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Open
Labels
Cursed?It's likely this is extremely difficult to fix without making something else much, much worseIt's likely this is extremely difficult to fix without making something else much, much worseNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
Description
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
}sinclairzx81, whzx5byb, unional, omril1 and danvkfatcerberus, MartinJohns, tonivj5 and KisaragiEffective
Metadata
Metadata
Assignees
Labels
Cursed?It's likely this is extremely difficult to fix without making something else much, much worseIt's likely this is extremely difficult to fix without making something else much, much worseNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone