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

Add null | undefined to Primitive and isPrimitive #113

Closed
dosentmatter opened this issue Oct 21, 2019 · 1 comment · Fixed by #116
Closed

Add null | undefined to Primitive and isPrimitive #113

dosentmatter opened this issue Oct 21, 2019 · 1 comment · Fixed by #116

Comments

@dosentmatter
Copy link
Contributor

dosentmatter commented Oct 21, 2019

Is your feature request related to a real problem or use-case?

See:
https://www.typescriptlang.org/docs/handbook/basic-types.html#object

object is a type that represents the non-primitive type, i.e. anything that is not number, string, boolean, symbol, null, or undefined.

Currently, we have export type Primitive = number | bigint | boolean | string | symbol;. We are missing null and undefined.

The complete list is

string | boolean | number | bigint | symbol | null | undefined

Describe a solution including usage in code example

export type Primitive = number | bigint | boolean | string | symbol | null | undefined;
export const isPrimitive = (val: unknown): val is Primitive => {
  if (val === null || val === undefined) {
    return true;
  }
  switch (typeof val) {
    case 'string':
    case 'symbol':
    case 'number':
    case 'bigint':
    case 'boolean': {
      return true;
    }
    default:
      return false;
  }
};

Who does this impact? Who is this for?

TypeScript users

@piotrwitek
Copy link
Owner

Hey @dosentmatter
This is a valid point and I agree with that.
Contributions welcome!

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