Skip to content

Regression: Error on indexing across compatible type parameters if constraint contains undefinedΒ #44166

Closed

Description

Bug Report

πŸ”Ž Search Terms

assignability regression

πŸ•— Version & Regression Information

  • This changed between versions 4.2.3 and 4.3.0-beta

⏯ Playground Link

Playground Link

πŸ’» Code

class TableBaseEnum<
    PublicSpec extends Record<keyof InternalSpec, any>,
    InternalSpec extends Record<keyof PublicSpec, any>  | undefined = undefined> {
    m() {
        let iSpec = null! as InternalSpec;

        // Error in 4.2 as expected. No error in 4.3 ❌        
        iSpec[null! as keyof InternalSpec]

        // Error in 4.2 because iSpec is possibly undefined βœ…
        // Error in 4.3 because keyof PublicSpec' cannot be used to index type InternalSpec ❌
        iSpec[null! as keyof PublicSpec]
        
        if (iSpec === undefined) {
            return;
        }
        // Ok in 4.2 and 4.3 as expected βœ…
        iSpec[null! as keyof InternalSpec]

        // Ok in 4.2, error in 4.3  βŒβ—
        iSpec[null! as keyof PublicSpec] 
        
    }
}

πŸ™ Actual behavior

  • before the check iSpec is indexable with keyof InternalSpec which seems like a safe null checks issue
  • after iSpec is checked, you can index with keyof InternalSpec but not keyof PublicSpec (even though PublicSpec is Record<keyof InternalSpec, any>)

πŸ™‚ Expected behavior

The behavior in 4.2 seems correct. If iSpec is not checked index access should give a possibly undefined error (it does not in 4.3) and after the check iSpec should be indexable with keyof InternalSpec or keyof PublicSpec

Activity

  1. added
    Needs Investigation
    on May 27, 2021
  2. added
    Bug
    and removed
    Needs Investigation
    on Jun 16, 2021
  3. added
    Fix Available
    on Jun 16, 2021
  4. 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

BugFix Available

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions