Skip to content

Record keys are inferred to be values when using extends string conditional in a generic type #53343

Description

@dk1a

Bug Report

🔎 Search Terms

inference generic extends record

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about "extends"

⏯ Playground Link

Playground link with relevant code

💻 Code

typeTestType<Keysextendsstring>=stringextendsKeys ? Record<Keys,string> : Record<Keys,string>functioninferHelper<Keysextendsstring>(data: TestType<Keys>){returndata;}exportconsta=inferHelper({// key1 is inferred to be value1 herekey1: "value1"})

🙁 Actual behavior

ts2345

Argument of type '{ key1: string; }' is not assignable to parameter of type 'Record<"value1", string>'.
Object literal may only specify known properties, and 'key1' does not exist in type 'Record<"value1", string>'

🙂 Expected behavior

no error, and the record is inferred as Record<"key1", string>

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: check: Type InferenceRelated to type inference performed during signature resolution or `infer` type resolutionFix AvailableA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions