TypeScript-de ýerleri üýtgetmek
Bizde käbir setir üýtgeýjisi bolsun:
let test: string = 'abc';
Ona başga bir setir ýerini ýazalyň:
let test: string = 'abc';
test = 'def';
Indi bolsa oňa san ýazmaga synanyşalyň. Bu ýagdaýda TypeScript ýalňyşlyk bildirer, sebäbi biz üýtgeýjiniň tipini üýtgetmäge synanyşýarys:
let test: string = 'abc';
test = 123; // ýalňyşlyk bildirer
Kody işletmezden öň, onuň işlenişiniň netijesi nähili bolar?
let test: number = 123;
test = 'abc';
console.log(test);
Kody işletmezden öň, onuň işlenişiniň netijesi nähili bolar?
let test: string = 'abc';
test = 123;
console.log(test);
Kody işletmezden öň, onuň işlenişiniň netijesi nähili bolar?
let test: string = 'abc';
test = '123';
console.log(test);
Kody işletmezden öň, onuň işlenişiniň netijesi nähili bolar?
let test: string = 'abc';
test = true;
console.log(test);
Kody işletmezden öň, onuň işlenişiniň netijesi nähili bolar?
let test: string = 123;
test = 'abc';
console.log(test);
Kody işletmezden öň, onuň işlenişiniň netijesi nähili bolar?
let test: string = '123';
test = '456';
console.log(test);
Kody işletmezden öň, onuň işlenişiniň netijesi nähili bolar?
let test: number = '123';
test = '456';
console.log(test);
Kody işletmezden öň, onuň işlenişiniň netijesi nähili bolar?
let test: number = 123;
test = 456;
console.log(test);
Kody işletmezden öň, onuň işlenişiniň netijesi nähili bolar?
let test: boolean = true;
test = false;
console.log(test);