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

Feature Request: Remove the string constraint from IsNever #109

Open
krisdages opened this issue Jun 28, 2019 · 0 comments
Open

Feature Request: Remove the string constraint from IsNever #109

krisdages opened this issue Jun 28, 2019 · 0 comments

Comments

@krisdages
Copy link

Fiddled around with this one for a while to try and find something that worked, pretty annoying!
Sure wish they would build something like these predicates into the language.

But I think I found a solution. I haven't tested this with keyofStringsOnly turned off, since it's still on in my project, but strangely, keyof never === keyof any === string.

export declare type IsNever<T> = keyof any extends keyof T ? If<IsAny<T>, False, True> : False;

//Examples
type IsNever_1 = IsNever<1>; //False
type IsNever_string = IsNever<string>; //False
type IsNever_null = IsNever<null>; //False
type IsNever_undefined = IsNever<undefined>; //False
type IsNever_void = IsNever<void>; //False
type IsNever_any = IsNever<any>; //False
type IsNever_never = IsNever<never>; //True
type IsNever_any_and_never = IsNever<any & never>; //True
type IsNever_any_or_never = IsNever<any | never>; //False
andnp added a commit that referenced this issue Jul 22, 2019
Thanks to @krisdages for finding this! This commit removes the `string`
condition on `IsNever` because `keyof never === keyof any === string`.

Closes: #109
andnp added a commit that referenced this issue Jul 22, 2019
Thanks to @krisdages for finding this! This commit removes the `string`
condition on `IsNever` because `keyof never === keyof any === string`.

Closes: #109
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

No branches or pull requests

1 participant