Difference between type[] and [type] in TypeScript

  • [string] denotes a tuple of type string. Tuples ordered lists of items. Finite and usually fixed sized. This type notation is for a tuple with exactly one string element.
  • string[] denotes an array of strings. Arrays will have variable size. Including even a size of zero.

The correct usage of the Tuple in your case would be:

let type2:WithStringArray2 = {
    property: ['someString']
};

See Documentation

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)