Azimio la Kubadilika
Ili kutangaza vigeu katika TypeScript
, tunatumia let
au const
maneno muhimu.
Kwa mfano: let num: number = 10;
au const message: string = "Hello";
Primitive Data Types
TypeScript
inasaidia primitive data types
kama vile number
, string
, boolean
, null
, na undefined
.
Kwa mfano: let age: number = 25;
,, let name: string = "John";
let isActive: boolean = true;
Array
Ili kutangaza safu katika TypeScript
, tunatumia type[]
sintaksia au Array<type>
.
Kwa mfano: let numbers: number[] = [1, 2, 3, 4, 5];
au let names: Array<string> = ["John", "Jane", "Alice"];
Object
Ili kufafanua aina ya data ya kitu, tunatumia {}
sintaksia na kubainisha aina ya kila sifa iliyo ndani yake.
Kwa mfano:
let person: {
name: string;
age: number;
isEmployed: boolean;
} = {
name: "John",
age: 25,
isEmployed: true
};
Function
TypeScript
huturuhusu kufafanua aina ya data ya vitendakazi.
Kwa mfano:
function add(a: number, b: number): number {
return a + b;
}
Hii ni baadhi ya mifano ya syntax ya msingi ya TypeScript na inayoungwa mkono data types, including primitive types, arrays, objects, and functions.
TypeScript
hutoa uwezo wa kupanua sintaksia na kuauni aina changamano zaidi za data ili kutosheleza mahitaji yako ya usanidi wa programu.