If we imagine having two interfaces:
interface WithStringArray1 {
property: [string]
}
interface WithStringArray2 {
property: string[]
}
Let's define variables of these types:
let type1:WithStringArray1 = {
property: []
}
let type2:WithStringArray2 = {
property: []
}
The first initialization results in an error message:
TS2322: Type '{ property: undefined[]; }' is not assignable to type 'WithStringArray1'.
Types of property 'property' are incompatible.
Type 'undefined[]' is not assignable to type '[string]'.
Property '0' is missing in type 'undefined[]'.
However, the second one is successful.
What sets apart [string]
from string[]
?