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.

Typescript types do not work on undefined as first parameter

See original GitHub issue

The following does not work:

          const myVar: { a: { b: string } } | null = null as {
            a: { b: string };
          } | null;
          const something = idx(myVar, _ => _.a.b);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
yungsterscommented, Dec 11, 2018

Thanks, @Horaddrim.

Sounds like this question has been resolved.

0reactions
macalinaocommented, Dec 24, 2018

@Horaddrim This doesn’t solve the problem for me.

    const myVar: { a: { b: string } } | null = null as {
      a: { b: string };
    } | null;
    const something = idx(myVar, _ => _.a.b) || "TEST";

still fails the build.

Please let me know if I failed any etiquette by opening a new issue. I’m not sure if I was supposed to do that-- sorry if I’m being annoying!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Do's and Don'ts - TypeScript
Don't ever use the types Number , String , Boolean , Symbol , or Object These types refer to non-primitive boxed objects that...
Read more >
typescript - Require argument if unknown type is not undefined
If a function parameter is optional, then it will accept undefined as a value. But the converse is not necessarily true; just because...
Read more >
typescript-cheatsheet - GitHub Pages
A set of TypeScript related notes used for quick reference. The cheatsheet contains references to types, classes, decorators, and many other TypeScript ......
Read more >
7 The essentials of TypeScript - Exploring JS
In this chapter, a type is simply a set of values. The JavaScript language (not TypeScript!) has only eight types: Undefined: the set...
Read more >
optional vs. undefined - TkDodo's blog
The first one means: This parameter is optional. ... because TypeScript was not complaining (I do rely on that a lot), as all...
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