javascript - What's the Difference between the two of writings of arrays in typescript -
typescript, javascript, allows work arrays of values. array types can written in 1 of 2 ways. in first, use type of elements followed '[]' denote array of element type:
var list:number[] = [1, 2, 3]; the second way uses generic array type, array:
var list:array<number> = [1, 2, 3]; are there difference between these 2 syntax? there reason 2 ways write these? (i know generics thing in other languages i've never used generics in past lang).
they equivalent. number[] form shorthand array<number> generic.
the "array type literal" section 3.7.4 of spec defined as:
an array type literal references array type (section 3.3.2) given element type.
the "array type" section 3.3.2 described as:
array types named type references created generic interface type 'array' in global module array element type type argument.
this notes arrays defined generic type argument. generic definitive version, description followed by:
array type literals (section 3.7.4) provide shorthand notation creating such references.
there no difference, type[] form exists shorthand using pre-existing js patterns.
Comments
Post a Comment