microsoft / microsoft/TypeScript
3.3.1 regression in type inference
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.3.1 & 3.4.0-dev.20190202
Search Terms:
Code
class Foo {
foo: number = 0;
}
class FooBar extends Foo {
bar: number = 10;
}
async function foo(f: Foo | number) {
if (f instanceof FooBar) {
try {
f = await (async (): Promise<Foo | number> => {
throw new Error();
})();
}
catch (ex) {
console.log(f.bar); // 3.3.1 has an error on this line -- "Property 'bar' does not exist on type 'number | Foo'. Property 'bar' does not exist on type 'number'"
}
}
}
foo(new FooBar());
Expected behavior:
No error as was in TypeScript 3.2.4
Actual behavior:
Error Property 'bar' does not exist on type 'number | Foo'. Property 'bar' does not exist on type 'number'
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
Reproduce the example from the linked TypeScript Playground using TypeScript 3.3.1, then compare its behavior with 3.2.4 and 3.4.0-dev.20190202. Trace how type inference handles the instanceof narrowing across the await assignment and catch block; done means f.bar no longer reports an error in the reported example.
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