Sanarwa mai canzawa
Don ayyana masu canji a cikin TypeScript
, muna amfani da kalmomi let
ko const
kalmomi.
Misali: let num: number = 10;
ko const message: string = "Hello";
Primitive Data Types
TypeScript
tallafi primitive data types
kamar number
, string
, boolean
, null
, da undefined
.
Misali: let age: number = 25;
,, let name: string = "John";
let isActive: boolean = true;
Array
Don ayyana jeri a ciki TypeScript
, muna amfani da type[]
ma'auni ko Array<type>
.
Misali: let numbers: number[] = [1, 2, 3, 4, 5];
ko let names: Array<string> = ["John", "Jane", "Alice"];
Object
Don ayyana nau'in bayanai don wani abu, muna amfani da {}
syntax kuma mu ƙayyade nau'in kowace dukiya da ke cikinsa.
Misali:
let person: {
name: string;
age: number;
isEmployed: boolean;
} = {
name: "John",
age: 25,
isEmployed: true
};
Function
TypeScript
yana ba mu damar ayyana nau'in bayanai don ayyuka.
Misali:
function add(a: number, b: number): number {
return a + b;
}
Waɗannan su ne wasu misalan ainihin ma'anar rubutu na TypeScript da masu goyan baya data types, including primitive types, arrays, objects, and functions.
TypeScript
yana ba da damar tsawaita tsarin aiki da goyan bayan nau'ikan bayanai masu rikitarwa don dacewa da buƙatun ci gaban aikace-aikacenku.