Skip to content

Error message refers to wrong key name after key remapping Β #44220

Closed
@jcalz

Description

@jcalz

Bug Report

πŸ”Ž Search Terms

key remapping, error message, 2345

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried since key remapping was introduced in TS4.1; I don't see relevant FAQ entries

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

function foo<T extends { [K in keyof T as `${Extract<K, string>}Oops`]: T[K] }>(x: T) { }
const x = { prop: 123 };
foo(x); // error!
//  ~ <-- Argument of type '{ prop: number; }' is not assignable to parameter of type '{ propOops: number; }'.
// Property 'prop' is missing in type '{ prop: number; }' but required in type '{ propOops: number; }'. (2345) 

πŸ™ Actual behavior

The last line of the error message says that the property prop is missing in the type { prop: number }, but it's not.

πŸ™‚ Expected behavior

The error should probably say

Property 'propOops' is missing in type '{ prop: number; }' but required in type '{ propOops: number; }'.

I guess the error message is using the original key when it should be using the remapped key? πŸ€·β€β™‚οΈ

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions