Closed
Description
Search Terms
TypePredicate
Suggestion
call a function with TypePredicate with an obviously true or obviously false argument is always useless,
and that maybe get a incorrect type guard, could we check this case or another limit set?
Use Cases
Examples
interface Node {
//...
}
interface Identity extends Node {
//...
}
interface WTFIdentity extends Identity {
//...
}
function isIdentity(node: Node) node is Identity {
// ...
}
function isWTFIdentity(node: Node) node is WTFIdentity {
// ...
}
declare const a: Identity;
declare const b: Identity | StringLiteral;
declare const c: StringLiteral;
isIdentity(a); // obviously true
isIdentity(b); // normal behavior
isIdentity(c); // obviously false
isWTFIdentity(a); // normal behavior
isWTFIdentity(b); // normal behavior
isWTFIdentity(c); // obviously false
Checklist
My suggestion meets these guidelines:
- [] This wouldn't be a breaking change in existing TypeScript / JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. new expression-level syntax)