-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
Out of ScopeThis idea sits outside of the TypeScript language design constraintsThis idea sits outside of the TypeScript language design constraints
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 falseChecklist
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)
Metadata
Metadata
Assignees
Labels
Out of ScopeThis idea sits outside of the TypeScript language design constraintsThis idea sits outside of the TypeScript language design constraints