``Typescript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale, it enables you to write JavaScript the way you want. it is a pure Object oriented programming language with class interface and static typing.
Why Use Typescript
- Compilation.
- Strong static typing.
- Supports type definition from existing JavaScript.
- Supports Object Oriented Programming Language.
Type System In Typescript.
Any : This is a super type of all types in typescripts.
Build In : This type consists of (String, Null, Number,
Array, Undefined, Boolean, Void and so on).User Define Type : The user defines the kind of type. e.g
(Classes, OOP and Enums)
How to declare an Array variable in Typescript.
The type syntax for declaring a variable in TypeScript is to include a colon (:) after the variable name, followed by its type. Just as in JavaScript, we use the var keyword to declare a variable. Declare its type and value in one statement.
When you declare a variable, you have four options −
1 Declare its type and value in one statement :
var [identifier] : [type] = value ;
2 Declare its type but no value. In this case, the variable will
be set to undefined:
var [identifier] : [type] ;
3 Declare its value but no type. The variable type will be set to
the data type of the assigned value.
var [identifier] = [value] ;
4 Declare neither value not type. In this case, the data type of
the variable will be any and will be initialized to undefined.
var [identifier] ;
Example: Variables in TypeScript
`
"use strict";
let a:number = 30;
a = "35";
let b:any = true
b = "red"
let c:undefined;
let z:null
let Uname:string = "Ade"
`
how to declare an object in Typescript
_
`
`var Data1: {
id : number | string;
name: string;
email: string;
height:number;
age: number;
}={
id : 234567890,
name: "adeola",
email: "abcdefhh123@gmail.com",
height: 50,
age: 25,
};``
How to declare an array in typescript
array
let carting: (string | number | boolean | null)[] = ["Addidas", 80, 90, null];
Top comments (0)