-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add an "argument is not type" operator #16812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Question
An issue which isn't directly actionable in code
Comments
Dupe (or heavily related to) #4183 |
function isNotUndefined<T>(obj: T | undefined): obj is T {
return typeof obj !== "undefined";
}
var x = Math.random() > 0.5 ? undefined : 32;
if (isNotUndefined(x)) {
console.log(x.toFixed());
} |
const test: (string | undefined)[] = []
test.filter(<T>(a: T): a is T | undefined => {
return !!a;
}).map(t => {
// t is string | undefined
}) |
@Arlen22 why did you write the predicate wrong? This works in 2.4: const test: (string | undefined)[] = []
test.filter(<T>(a: T | undefined): a is T => {
return !!a;
}).map(t => {
t;
// t is string
}) |
const test: (string | undefined)[] = []
test.filter(<T>(a: T | undefined): a is T => {
return !!a;
}).map(t => {
let r: string = t; //Error: Type 'string | undefined' is not assignable to type 'string'
}) |
Nevermind, I forgot to update my global tsc. Now I'm seeing the new feature. Nice :) |
Any idea what PR brought this in? |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Uh oh!
There was an error while loading. Please reload this page.
We already have:
Now we just need:
The text was updated successfully, but these errors were encountered: