menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Declare an...
source image

Dev

4d

read

52

img
dot

Image Credit: Dev

Declare an array in TypeScript

  • In JavaScript, you declare an array like this: const fruits = ['apple', 'orange', 'banana'];
  • In TypeScript, declare an array with type like this: const fruits: string[] = ['apple', 'orange', 'banana'];
  • Avoid declaring an empty array with const fruits: [] = [], as it's incorrect in TypeScript.
  • Also, refrain from using 'any' type in arrays in TypeScript, like const fruits: any[] = [1, 2, 3].

Read Full Article

like

3 Likes

For uninterrupted reading, download the app