gajus / database-types

A generic type generator for various databases.
Other
26 stars 3 forks source link

better handle of not null #7

Closed sibelius closed 7 years ago

sibelius commented 7 years ago

current output:

updatedAt: string | null

it should be updatedAt?: string

gajus commented 7 years ago

Whats wrong with string | null for a nullable type?

sibelius commented 7 years ago

I think it is the same, I little bit more verbose

gajus commented 7 years ago

It is not the same.

?: allows omission of the property.

| null allows value to be null, but does not allow omission of the property.

The difference is important, because in one case you need to do check such as movie.updatedAt && movie.updatedAt === 'something' and in the | null case just movie.updatedAt === 'something' is enough.

sibelius commented 7 years ago

what about

updatedAt: ?string

?

gajus commented 7 years ago

Looks like thats a shortcut for | null.

I have not seen it in the docs, but it is documented here.

https://stackoverflow.com/a/37174244/368691