Skip to content

typeof item in Array incrorrect #46304

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

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