DEV Community

Cover image for TypeScript Basics - A Definitive Guide

TypeScript Basics - A Definitive Guide

GaneshMani on October 20, 2019

In this article, we will learn some basics of typescript which helps you to develop javascript application in a better way. TypeScript Basics - A D...
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.. :-)

Collapse
 
simonholdorf profile image
Simon Holdorf

I wonder who started that thing with those He-Man images......

Collapse
 
ganeshmani profile image
GaneshMani

Me too...but i like that combo... that's why I kept it ..

Collapse
 
imthedeveloper profile image
ImTheDeveloper

Have you had any experience converting an existing project over to typescript? Is there a way of slowly accomplishing the task or is it an all or nothing route?

Collapse
 
akashkava profile image
Akash Kava

Typescript allows you to declare type declarations, in which you can create definitions of old code and write new code in TypeScript. Slowly you can even rewrite old code in TypeScript one file at a time, and since TypeScript's output is pure JavaScript, your code can co exist along with old plain JavaScript and New TypeScript generated JavaScript.