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

Have a single way to represent absent values: use undefined #156

Open
Que3216 opened this issue Mar 8, 2021 · 1 comment
Open

Have a single way to represent absent values: use undefined #156

Que3216 opened this issue Mar 8, 2021 · 1 comment

Comments

@Que3216
Copy link

Que3216 commented Mar 8, 2021

The typescript coding guidelines state:

Use undefined. Do not use null.

https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines#null-and-undefined

Standardizing on one helps prevent bugs (due to comparisons between the two; or due to === undefined checks, when the value is really null). Using the two to represent different semantics usually leads to more confusing code. In addition since Java can't distinguish between the two any undefineds are converted to nulls after a write and a read.

Should we therefore:

  1. Update all Conjure generated typescript typings to be '| undefined' only (instead of | undefined | null)?
  2. Update the generated Conjure clients to automatically convert any nulls to undefined on deserialization?

This would be an API break, so would have to be opt in --- ideally opt-in on the client side (maybe we have Conjure publish two versions of the typescript typings, a v1 and a v2?). The goal would be to reduce bugs from null vs undefined mismatches, and just have a single way of representing optional values.

@p-szm
Copy link
Contributor

p-szm commented Jun 28, 2021

I just wanted to flag that the coding guidelines that you linked to are only for contributing to TypeScript itself, and are not general TypeScript coding guidelines. See this warning at the top of the page:

These are Coding Guidelines for Contributors to TypeScript. This is NOT a prescriptive guideline for the TypeScript > community. These guidelines are meant for contributors to the TypeScript project's codebase. We have chosen many of them > for team consistency. Feel free to adopt them for your own team.

AGAIN: This is NOT a prescriptive guideline for the TypeScript community

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

2 participants