In typescript, What is right thing?
[string] vs string[]
public searchOption: [string] = ['date']; public searchOption: string[] = ['date'];
In TypeScript, the string is sequence of char values and also considered as an object. It is a type of primitive data type that is used to store text data. The string values are used between single quotation marks or double quotation marks, and also array of characters works same as a string.
String[] and String... are the same thing internally, i. e., an array of Strings. The difference is that when you use a varargs parameter ( String... ) you can call the method like: public void myMethod( String... foo ) { // do something // foo is an array (String[]) internally System.
There's no difference between the two, it's the same.
TypeScript: String vs string 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible.
The first is a tuple and the second is an array of strings.
You can do this with tuples:
let searchOption: [string, number] = ['date', 22];
The second one is right. If you want, you can take a look here https://www.typescriptlang.org/docs/handbook/basic-types.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With