Skip to content

Type 'string | number' is not assignable to type 'never'. Type 'string' is not assignable to type 'never'.Β #44909

Closed
@Azevedo-Dani

Description

@Azevedo-Dani

Bug Report

πŸ•— Version & Regression Information

  • Compilation error
  • This is the behaviour in every version I tried. Since 3.5.1

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

interface IItem {
    id: number
    name: string
}

const item: IItem = {
    id: 1,
    name: 'item1'
}

const fun1 = (item: IItem, value: IItem[keyof IItem], name: keyof IItem) => {
    item[name] = value
}

const fun2 =  <T extends IItem>(item: T, value: T[keyof T], name: keyof T) => {
    item[name] = value
}

πŸ™ Actual behaviour

There's an error in fun1. We can't do item[name] = value otherwise we have the error Type 'string | number' is not assignable to type 'never'. Type 'string' is not assignable to type 'never'.

But the fun2 works perfectly.

πŸ™‚ Expected behaviour

We should have the same behaviour in fun1 and fun2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions