Reputation: 3423
My goal is to open a subscription to an rxjs subject, with the type string | undefined
.
My code looks like this:
import {Subject, Observable} from 'rxjs';
const a = new Subject<string | undefined>();
// v has type "string", and not "string | undefined"
a.subscribe(v => console.log(v));
How can I get v
to have the type string | undefined
?
Here is a stackblitz if you wan't to experiment.
Upvotes: 3
Views: 66
Reputation: 3594
You must have strictNullChecks
compiler option enabled: http://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options
Upvotes: 4