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

not operator (anything but) #139

Closed
Mouvedia opened this issue May 10, 2018 · 6 comments · Fixed by #140
Closed

not operator (anything but) #139

Mouvedia opened this issue May 10, 2018 · 6 comments · Fixed by #140

Comments

@Mouvedia
Copy link
Collaborator

Mouvedia commented May 10, 2018

tl;dr:

(param: Any) => not String
// shorthand
(param: Any) => !String

// union case
(param: Any) => not(String | Array)
// short hand
(param: Any) => !(String | Array)

Sometimes it's way easier and convenient to define the type by discarding one or several.
There's also the possibility to define it as a substraction—e.g. Any - String—but that would not be very conventional.

TypeScript approaches

@ericelliott
Copy link
Owner

I like it.

@Mouvedia
Copy link
Collaborator Author

Mouvedia commented May 16, 2018

After thinking about it I think that introducing a new keyword is not a good idea: we should be as JS compatible as possible. It's not ruby after all. Ill do a PR if I find an acceptable title for the chapter.

Still Iv got a problem:

// if & is introduced
!(A | B)
// could be expanded to
!A | !B
// which is not
!A & !B

Ill have to poke #132 in this PR.

@ericelliott
Copy link
Owner

After thinking about it I think that introducing a new keyword is not a good idea: we should be as JS compatible as possible. It's not ruby after all.

I'm not sure what you mean by this. JavaScript has a logical ! operator which behaves similarly.

// if & is introduced
!(A | B)
// could be expanded to
!A | !B
// which is not
!A & !B

I don't see this as a problem, as long as it is well documented.

@ericelliott
Copy link
Owner

My biggest problem with this proposal is that ! type declarations can't be future-compatible. Because they blacklist instead of whitelist types, newly introduced types may be considered acceptable by the type system, even if they're not acceptable types in practice.

@ericelliott ericelliott removed the ready label May 16, 2018
@Mouvedia
Copy link
Collaborator Author

Mouvedia commented May 16, 2018

I'm not sure what you mean by this.

I was talking about not.

I don't see this as a problem, as long as it is well documented.

Do you have an example in mind?

@Mouvedia
Copy link
Collaborator Author

Mouvedia commented May 16, 2018

newly introduced types may be considered acceptable by the type system, even if they're not acceptable types in practice

That's to be expected. Let's say you had !Array before typed arrays were introduced and it doesn't cover Int16Array, I wouldn't blame rtype. The type will have to be updated to !Array & !TypedArray; it's such a rare occurence that I don't mind.

Mouvedia added a commit that referenced this issue May 16, 2018
@Mouvedia Mouvedia mentioned this issue May 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants