microsoft / microsoft/TypeScript
Any type is inferred when function input parameter is set to some value
Open
Nobody has claimed this yet.
Bug
Domain: check: Type Inference
Needs Human Review
Needs More Info
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.8.2
Search Terms: any type is inferred
Code
interface ContinuationQueryResult<T> {
documents: T[];
continuation?: string;
}
function abc(continuation?: string): Promise<ContinuationQueryResult<string>> {
return <any>undefined;
}
async function test() {
// When not explicitly set to undefined type is inferred correctly.
let continuation: string | undefined = undefined;
do {
const summaries = await abc(continuation);
continuation = summaries.continuation;
} while (continuation)
}
Expected behavior:
Type of summaries variable should be ContinuationQueryResult<string>.
Actual behavior:
summaries variable is inferred as any.
Related Issues:
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 linked TypeScript Playground reproduction and the test function, comparing inference when continuation is initialized to undefined versus another value. Trace the type-checking path for the optional argument and add a regression test; done means summaries is inferred as ContinuationQueryResult rather than any.
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
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100