Improve getNodeProperty by using conditional types
See original GitHub issueLooks like this:
export type TsNodePropertyNames<NodeType extends ts.Node> = {
[KeyName in keyof NodeType]:
KeyName extends "_tsSimpleAstBrand" | CompilerApiNodeBrandPropertyNamesType ? never : KeyName;
}[keyof NodeType];
export type TsNodeToWrappedType<NodeType extends ts.Node, KeyName extends TsNodePropertyNames<NodeType>, NonNullableNodeType = NonNullable<NodeType[KeyName]>> =
NodeType[KeyName] extends ts.NodeArray<infer ArrayNodeType> ? Node<ArrayNodeType>[] :
NodeType[KeyName] extends ts.Node ? Node<NodeType[KeyName]> :
NonNullableNodeType extends ts.Node ? Node<NonNullableNodeType> | undefined :
NodeType[KeyName];
But unfortunately only compiles in typescript@next due to bugs so I’ll have to wait. Maybe it will work in the next 2.8.x version. In the meantime, I’ve checked this into the getNodeProperty branch.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Documentation - Conditional Types
Generating types by re-using an existing type. The TypeScript docs are an open source project. Help us improve these pages by sending a...
Read more >The guide to conditional types in TypeScript
It is so common to use conditional types to apply constraints and extract properties' types that we can use a sugared syntax for...
Read more >Conditional types in TypeScript
In this post I'll familiarize you with the concept of the conditional types and provide several simple use cases.
Read more >Conditional types in TypeScript - Artsy Engineering
Here we've introduced a type variable T for the text parameter. We can then use T as part of a conditional return type:...
Read more >The Four Types of Conditionals and How to Use Them
It's just a matter of learning the basic grammar rules. So, to get a better understanding of how they work, we will look...
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
@lazarljubenovic it might be nice in some scenarios, but it’s good for people to prompted about something possibly being possibly null and then from there decide whether they want to handle it being null or do something else like throwing an exception.
I’m personally using
orThrow
variants so much I’d almost prefer them being the regular ones and the othersorNull
. 😅