DEV Community

Discussion on: TypeScript Basics - A Definitive Guide

Collapse
 
khylias profile image
Vincent Kraus • Edited

Nice one !
I recommand you to use const rather than let if you didn't reassign variable as :

const createNewArray = <T>(value: T): Array<T> => {
    const output : Array<string> = [];

    output.push(value);

    return output;
}

And last tips, you can declare type array as below for an array of string.

const output: string[] = []; // Array of string
const output2: number[]; // Array of number, etc...
Collapse
 
ganeshmani profile image
GaneshMani

Sure.. will change it..thanks for the heads up.. :-)