Skip to content

TS 4.2: Type alias differs from original typeΒ #44119

Closed

Description

Bug Report

πŸ”Ž Search Terms

4.2 Type alias

πŸ•— Version & Regression Information

  • This changed between versions 4.1.5 and 4.2.3
  • Also reproducible in 4.3.0-beta and nightly

⏯ Playground Link

Playground link

πŸ’» Code

const func1 = (arg: Record<'field', string>) => { }

type Type1 = Record<'field', string>
const func2 = (arg: Type1) => { }

const arg: Record<string, string> = {}

func1(arg) // ok
func2(arg) // Property 'field' is missing in type 'Record<string, string>' but required in type 'Type1'.

πŸ™ Actual behavior

Type alias Type1 differs from original type Record<'field', string>

πŸ™‚ Expected behavior

Types of func1 and func2 should be equal and behave the same way, as it worked on 4.1.5 and earlier

Activity

  1. ahejlsberg commented on May 26, 2021

    @ahejlsberg
    Member

    The direct cause of this issue is #42284. We now preserve the alias for Type1 and thus when relating to Record<'field', string> we are no longer relating instantiations of the same type alias. Therefore we relate the types structurally and we discover they're not compatible. The reason we view Record<'field', string> and Record<string, string> as compatible has to do with the way we measure variance. We find that the first type parameter is contra-variant when in reality variance is strictly speaking unmeasurable for mapped types because a string key turns into an index signature which doesn't exactly behave as an infinite number of properties.

    I'm pretty sure we already have a bug for this, but haven't been able to find it yet.

  2. ahejlsberg commented on May 26, 2021

    @ahejlsberg
    Member

    I should add, I think we already tried marking variance of mapped types as unmeasurable, but it lead to an explosion in structural type comparisons with significant effects on performance.

  3. ahejlsberg commented on May 26, 2021

    @ahejlsberg
    Member

    I found the issue we already have for this. Duplicate of #29698.

  4. added
    DuplicateAn existing issue was already created
    and removed
    BugA bug in TypeScript
    on Jun 16, 2021
  5. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

DuplicateAn existing issue was already created

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions