question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve getNodeProperty by using conditional types

See original GitHub issue

Looks 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:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dsherretcommented, Jun 3, 2018

@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.

0reactions
lazarljubenoviccommented, May 27, 2018

I’m personally using orThrow variants so much I’d almost prefer them being the regular ones and the others orNull. 😅

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found