Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With optional it does not work with null #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

unional
Copy link
Collaborator

@unional unional commented Jun 26, 2016

No description provided.

@blakeembrey
Copy link
Member

Using null is a TypeScript nightly only feature and breaks everyone using a stable release.

@unional
Copy link
Collaborator Author

unional commented Jun 26, 2016

Yeah, any alternative solution?

@blakeembrey
Copy link
Member

Not that I know of, I've worked around it in other places by using void, but that doesn't allow null - just undefined.

@louy
Copy link
Member

louy commented Jun 26, 2016

AFAIK null = any > void. So it should work.

@blakeembrey
Copy link
Member

@louy Sorry, I didn't understand that notation?

@louy
Copy link
Member

louy commented Jun 26, 2016

Sorry. I meant any contains void. Couldn't find the symbol on my keyboard.

In TS 1.8 null has type any, meaning that if you pass null as void it should work fine.

For example:

function test(x: void) {}
test(null); // <-- no errors

@louy
Copy link
Member

louy commented Jun 26, 2016

I've just realised that the problem @unional is having is with TS nightly as null should work fine with the current typing (there wasn't much context for this PR).

I don't think we can do anything about this for now to make it work with both versions. Anyway non-nullable types are a version 2.0 feature so I think we don't have to worry about them for now.

@unional
Copy link
Collaborator Author

unional commented Jun 26, 2016

@louy yeah, notice that it is working fine when I actually open this project and run the tests.

Wouldn't it be a backward compatibility issue with nullable type? Seems like this will break a lot of typings when TS 2.0 is released.

@blakeembrey
Copy link
Member

Absolutely, it kind of does - but that's what a 2.0 is for, I suppose. I've been having a pretty good run using strictNullChecks and the nightlies for around 3 months on the current project. The only thing I've changed is typings where I used void (which is really the only backward-compatible way to partially fix this).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants