yayoc / optional-chain

⛓Optional chaining implementation in TypeScript
https://github.com/yayoc/optional-chain
MIT License
19 stars 2 forks source link

Running latest example doesn't work with TS 2.7.2 #3

Closed henrikra closed 6 years ago

henrikra commented 6 years ago

When running following code with TS 2.7.2

type User = {
  name?: {
    first: string
  }
}
const user: User = {name: null};
const optionalUser = optional(user);
optionalUser.k("name").k("first").get();

I will get error Property 'get' does not exist on type 'Option<string>'

image

What is wrong? With TS 2.9.2 I will not get error. Problem is that I am not able to upgrade TS yet because of other problems

henrikra commented 6 years ago

Hmm I guess it is because of this line: https://github.com/yayoc/optional-chain/blob/master/src/index.ts#L10 Since conditional types came to TS in 2.8 :/

yayoc commented 6 years ago

Yes, This library requires TS 2.8+ to use conditional types.

henrikra commented 6 years ago

Maybe you should add it to README?

yayoc commented 6 years ago

I noted the requirement on README, Thanks.

henrikra commented 6 years ago

Very nice! I am able to test this in couple weeks since then I can update to TS 2.8. Have you used this library in production yet or just hobby projects?