Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
136 views
in Technique[技术] by (71.8m points)

Confussion on case in types in typescript

While reviewing some code, I came across a mix of capitalized types in a typescript document.

Is there an actual difference between these - because VSCode, colorizes them differently and gives reference for caps, and no ref for all lower (string vs. String etc)

errorMessage: String = '';  
errorShow: Boolean = false; 

errorMessage: string = '';  
errorShow: boolean = false; 

I've had no problems running the code either way - but am curious if there is a distinction / difference

question from:https://stackoverflow.com/questions/65943330/confussion-on-case-in-types-in-typescript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

String is the JavaScript String type, which you could use to create new strings. Nobody does this as in JavaScript the literals are considered better, so s2 in the example above creates a new string without the use of the new keyword and without explicitly using the String object.

string is the TypeScript string type, which you can use to type variables, parameters and return values.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...