DEV Community

Discussion on: Typescript Quirks - String or string? Which one should I use?

Collapse
 
baenencalin profile image
Calin Baenen

Also, I believe with String, you can have a null value, and with string, you can't (at least in any typed-language that doesn't support type-reassignment (i.e. Typescript(?)), though, I could be wrong, since I'm basing this off of my knowledge with C# and Java objects).

Collapse
 
sidthesloth92 profile image
Dinesh Balaji • Edited

Since Typescript is a superset of JS (which does not have types), you can assign null to string as well. But if you want to opt out of this behaviour, in your tsconfig you can set, strictNullChecks to true. Now you won't be able to assign null to a string variable.

Collapse
 
baenencalin profile image
Calin Baenen

Yeah. Cool.
Though, I only wish there was a way to use TS in the browser natively, I know it has to be "converted" to JS, but like, why can't we just have it interpreted like JS, and have that as another option? It'd save a hassle.

Thread Thread
 
sidthesloth92 profile image
Dinesh Balaji

I would love that as well.. :D

Thread Thread
 
baenencalin profile image
Calin Baenen • Edited

I mean, the script tag NEEDS another use, bc outside if js, it's useless.
If I knew how to make, or modify a browser, I wold make such a thing.

#NativeTSSupport