Open LeviticusMB opened 4 years ago
The error may stem from doSomething
inferring the wrong type for T
, as doSomething(readEvents())
seems to infer T
to { type: "number"; value: number; }
and not MyEvent
. The error also goes away if you write doSomething<MyEvent>(readEvents());
instead. I will need to investigate further to determine if this is something we can improve on.
I've run into a weird problem in a project that uses async generators. I've reduced the problematic code to the example below, which also fails in a similar way that my actual code does.
There seem to be several conditions that must be fulfilled:
T
is a union.T
(withWithID
in the example).null
andundefiened
.T
and eithernull
orundefined
(but not both).Change just any of these conditions in the playground, and the error goes away ...
TypeScript Version: 4.0.0-beta (and below)
Search Terms: generator null undefined
Expected behavior: No errors.
Actual behavior: A strange error message when
doSomething()
is called.Related Issues: No
Code
Output
```ts "use strict"; //interface MyEvent { type: "number" | "string", value: number | string }; function doSomething(gen) { // ... } function* readEvents() { yield undefined; } doSomething(readEvents()); ```Compiler Options
```json { "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true, "strictFunctionTypes": true, "strictPropertyInitialization": true, "strictBindCallApply": true, "noImplicitThis": true, "noImplicitReturns": true, "alwaysStrict": true, "esModuleInterop": true, "declaration": true, "experimentalDecorators": true, "emitDecoratorMetadata": true, "moduleResolution": 2, "target": "ES2019", "jsx": "React", "module": "ESNext" } } ```Playground Link: Provided