I need to pass this array into my function using Typescript:
const message = [ 'c', 'a', 'k', 'e', ' ',
'p', 'o', 'u', 'n', 'd', ' ',
's', 't', 'e', 'a', 'l' ];
As TypeScript doesn't have a type for a fixed length character, I'm not sure what is the best way to pass in the array to my function.
Right now I'm calling it like this but I want to do it in a better way
function reverseWords(wordArray :any[]): any[]{
}
I also tried using generics to make sure the input and output were the same but got the error "Type 'string' is not assignable to type 'T'"
function reverseWords<T>(wordArray: Array<T>): Array<T> {
return ["c", "a", "k", "e"];
}
Thanks so much for any guidance on this, I'm clearly new to Type Script.
string[]as the type?