Skip to content

typeof item in Array incrorrectΒ #46304

Closed
Closed
@kikyouink

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