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

literals should accept null #685

Closed
KristjanTammekivi opened this issue Jun 27, 2023 · 3 comments · Fixed by #698
Closed

literals should accept null #685

KristjanTammekivi opened this issue Jun 27, 2023 · 3 comments · Fixed by #698
Assignees
Labels
invalid This doesn't seem right question Further information is requested

Comments

@KristjanTammekivi
Copy link
Contributor

KristjanTammekivi commented Jun 27, 2023

Feature Request

https://typia.io/playground/?script=JYWwDg9gTgLgBDAnmYBDOAzKERwERIqp4DcAUGYWgHQA2wMAplKrQM4A8A5AIJdwAfOADsArrVoA+ABQBKIA

Currently null does not work, the extends for literals does not allow for it and when suppressing the error it just omits the value from the array

@samchon
Copy link
Owner

samchon commented Jun 29, 2023

I think that null cannot be distinguished as constant literal value of atomic values.

In JS classification, null is a type of object. Therefore, current typia supports only those types in literals function.

  • boolean
  • number
  • bigint
  • string

@samchon samchon self-assigned this Jun 29, 2023
@samchon samchon added invalid This doesn't seem right question Further information is requested labels Jun 29, 2023
@KristjanTammekivi
Copy link
Contributor Author

I don't quite see how that affects it, I managed to add a few lines of code into literalsProgrammer to get nulls to work

image

I'd happily take a closer look at the original code but I can't seem to get the tests to work

A bit off topic: I wanted to add a github action step to check that the test:generate has been run, seemed to notify just fine, but after running test:generate the tests don't seem to pass https://github.com/KristjanTammekivi/typia/actions/runs/5414154249/jobs/9840790293

@samchon
Copy link
Owner

samchon commented Jun 30, 2023

You can just check nullable through Metadata.nullable property in the LiteralsProgrammer.

Also, you have to change generic type of literals function to like below:

export function literals<T extends Atomic.Type | null>(): T[];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants