the "is" keyword (type predicates)
See original GitHub issueTo allow for type refinement to be abstracted into functions:
function isNumber(n: unknown): n is number {
if (typeof n === 'number' && !isNaN(n)) return true
return false
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
What does the `is` keyword do in typescript? - Stack Overflow
A type predicate is just used in compile time. The resulting .js file (runtime) will have no difference because it does not consider...
Read more >Documentation - Advanced Types - TypeScript
A predicate takes the form parameterName is Type , where parameterName must be the name of a parameter from the current function signature....
Read more >Aha! Understanding Typescript's Type Predicates
Type predicates are a special return type that signals to the Typescript compiler what type a particular value is. Type predicates are always ......
Read more >What is this return type with "is" keyword. : r/typescript - Reddit
It's called Type Predicate and is used in the context narrowing down the type of a value. For your example it'd mean that...
Read more >Type predicate expressions and 'this' type assertions #12942
I'll try to break down what is happening here: The SameKeys type contains a type expression that evaluates to either the true or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@JSMonk you should allow developer to specify what he/she wants to refine to so refinement itself can be checked against expectation of a developer
for example
of course inference of
$Refine
would be super cool but developer needs to be able to specify intentThat’s a good point. It could be possible to make a mistake in the return statement, and therefore by accident change the type guard that the boolean represents.