Skip to content

Bug: Intellisense shows misleading error when parameter is expected to be a union of an object and a stringΒ #45217

Open
@devanshj

Description

@devanshj

Bug Report

πŸ”Ž Search Terms

Intellisense, incorrect function parameter

πŸ•— Version & Regression Information

Tried with v4.3.5

⏯ Playground Link

Playground

πŸ’» Code

declare const send:
  (event: { type: "A", foo: string } | { type: "B" } | "B") => void

declare const sendOnlyObject:
  (event: { type: "A", foo: string } | { type: "B" }) => void


send({ type: "A" })
// Type '"A"' is not assignable to type '"B"'.(2322)

sendOnlyObject({ type: "A" })
// Argument of type '{ type: "A"; }' is not assignable to parameter of type '{ type: "A"; foo: string; } | { type: "B"; }'.
//   Property 'foo' is missing in type '{ type: "A"; }' but required in type '{ type: "A"; foo: string; }'.(2345)

πŸ™ Actual behavior

The error for send({ type: "A" }) is Type '"A"' is not assignable to type '"B"'

πŸ™‚ Expected behavior

The error should be something like the one for sendOnlyObject or at least not misleading that the property type has to be "B" that's what is getting suggested here.

Metadata

Metadata

Assignees

Labels

Domain: Error MessagesThe issue relates to error messagingEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Experience EnhancementNoncontroversial enhancementsHelp WantedYou can do thisRescheduledThis issue was previously scheduled to an earlier milestoneSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions