Skip to content

typeof item in Array incrorrectΒ #46304

Closed
Closed

Description

@kikyouink

Bug Report

text[key] on left infer to never ??? but why text[key] on right infer to string | number?

πŸ”Ž Search Terms

πŸ•— Version & Regression Information

typescript - 4.5.0

  • This is a crash

⏯ Playground Link

link

πŸ’» Code

interface Item {
    id: number;
    name: string;
    age: number;
}

const form: Item = {
    id: 99,
    name: 'k',
    age: 99,
};

const text: Item = {
    id: 1,
    name: 'εΌ δΈ‰',
    age: 18,
};

(['id','name','age'] as const).forEach(key => {
    text[key] = text[key];
});

// Type 'string | number' is not assignable to type 'never'.
// Type 'string' is not assignable to type 'never'.

πŸ™ Actual behavior

bug occured

πŸ™‚ Expected behavior

no bug

Activity

  1. jcalz commented on Oct 11, 2021

    @jcalz
    Contributor

    Working as intended, as per #30769. Possible duplicate of #32693

  2. fatcerberus commented on Oct 11, 2021

    @fatcerberus

    This is a crash

    Uh... no it's not? Nor is it a bug. It's just an error you didn't expect.

  3. typescript-bot commented on Oct 14, 2021

    @typescript-bot
    Contributor

    This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  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

Assignees

No one assigned

    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