Issue
Here is the variable declaration with type any:
let errorMessagesBag: any = []
erroMessagesBag must be able to hold a variable number of values that can be either a string, or a tuple of strings. Example
let errorMessagesBag = ["string1", ["tuplestring1", "otherString"], "string2"] // and so on
How to replace 'any' with proper type declaration in this case, so it accepts an array that contains strings OR a tuples of strings ?
Solution
With union types:
let errorMessagesBag: (string | string[])[] = []
or
let errorMessagesBag: Array<string | string[]> = []
The two syntaxes are equivalent.
Answered By - Paleo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.