Skip to content

quick fix to fill in missing properties not available on mapped type #51163

@snowpuddles

Description

@snowpuddles

Bug Report

🔎 Search Terms

"quick fix mapped type" "add missing properties mapped type"

🕗 Version & Regression Information

  • Based on changing version with the playground below, 4.5+ when quick fix was added
  • Behavior is still present on Nightly

⏯ Playground Link

Playground link with relevant code

💻 Code

See playground link for full example.

interface BasicType{
  numb: number,
  name: string,
}
interface OtherType{
  bool: boolean
}
interface MappingType{
  basic: BasicType,
  other: OtherType
}
function test2<T extends keyof MappingType>(type: T, obj: MappingType[T]):string{
  return "arbitrary"
}
//TS2345, understands `obj` is of type `BasicType`, `quick fix` not available
const val2 = test2("basic",{});

🙁 Actual behavior

  • TS-2345 for both lines in the playground.

  • quick fix is available for function call using type directly.

image

  • quick fix is not available for function call using mapped type even though TS does understand its type.

image

Error message is the same for both:

Argument of type '{}' is not assignable to parameter of type 'BasicType'.
  Type '{}' is missing the following properties from type 'BasicType': numb, name(2345)

🙂 Expected behavior

  • TS-2345 for both lines in the playground.
  • quick fix for TS-2345 to "add missing properties" to be available on both empty function call parameters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Experience EnhancementNoncontroversial enhancementsFixedA PR has been merged for this issueHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions