microsoft / microsoft/TypeScript
Type parameter gets optionalized during call signature comparison
Open
Nobody has claimed this yet.
Bug
Domain: check: Variance Relationships
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Bug Report
🔎 Search Terms
type parameter union undefined optional
🕗 Version & Regression Information
3.3.3333, 4.1.3, master (303ed3a357)
⏯ Playground Link
Playground link with relevant code
💻 Code
interface A {
<T>(
executor: (
resolve: {
(value: T): void;
} & {
(value?: T): void;
}
) => void
): T;
}
interface B {
<T>(
executor: (
resolve: {
(value: T): void;
} & {
(value?: T): void;
}
) => void
): T;
}
const a: B = {} as A;
🙁 Actual behavior
Compile error at the last line:
Type 'A' is not assignable to type 'B'.
Type 'T | undefined' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'T | undefined'.
Type 'undefined' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'undefined'.
🙂 Expected behavior
There should be no compile error, as A and B have exactly the same definition.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the assignment error from the linked Playground example and inspect the compiler's call-signature comparison and type-parameter handling. Trace why the identical definitions produce T | undefined versus T, then verify that the example compiles without error while preserving the reported behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100