microsoft / microsoft/TypeScript
Incorrectly typed argument variant
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.8.3
Search Terms:
Parameters, Array, Overloading, Type inference
Code
type VariantA = [(err: Error, data: string) => any]
type VariantB = [(data: string) => any, (err: Error) => any]
type Args = VariantA | VariantB
function fn (...rest: Args): void { /* do something */ }
fn((err, data) => {
err.stack // Correct: Typed as Error
data.charAt(0) // Correct: Typed as string
})
fn((data) => {
data // --> Error: Mistyped as any, should be string <--
}, (err) => {
err.stack // Correct: Typed as Error
})
Expected behavior:
If two functions are passed in (VariantB), the first paramter should be typed as data: string.
Actual behavior:
If two functions are passed in, the first function's parameter is typed as any.
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 with the minimal TypeScript reproduction in the issue and compare contextual typing for the one-callback and two-callback calls. Trace the type inference and overload handling for the union rest parameter, then verify that the first callback parameter is inferred as string without regressing the Error and data typings.
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
- 42/100