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

classnames also accept undefined as value #751

Merged
merged 3 commits into from
Jul 7, 2018

Conversation

siuvdlec
Copy link
Contributor

@siuvdlec siuvdlec commented Jul 6, 2018

What:

Why:

How:

Checklist:

  • Documentation
  • Tests
  • Code complete

@@ -32,7 +32,7 @@ export interface ArrayClassNameArg extends Array<ClassNameArg> {}

export type ClassNameArg =
| undefined | null | boolean | string
| { [key: string]: boolean }
| { [key: string]: boolean | undefined }
Copy link
Member

@tkh44 tkh44 Jul 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this need to support all of these types (undefined | null | boolean | string) as values?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need any, as described in #746.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while any is technically correct I doubt we should actually recommend it, typings give us power to restrict usages to sane ones

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it's better with undefined | null | boolean | string

Copy link
Member

@emmatown emmatown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!!

@emmatown emmatown merged commit b0476b4 into emotion-js:master Jul 7, 2018
@osi-oswald
Copy link

Why was type number not added as well? Consider the following usecase:

cx('count', { isOdd: count % 2 }) // TS complains, emotion handles it just fine

I now have to type one of the following just to make TS happy again (which I find unnecessary):

cx('count', { Boolean(isOdd: count % 2) })
cx('count', { !!(isOdd: count % 2) })

Actually type any would really be the best type for it. Otherwise someone might come and ask "why did you not add type XXX as well"?

@Andarist
Copy link
Member

Andarist commented Oct 4, 2018

Imho relaying on auto bool coercion for numbers there is not the best way to do. While it ofc works in JavaScript, type systems should strive to be more explicit about such things and I would consider the current lack of number support a good thing.

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

Successfully merging this pull request may close these issues.

6 participants