This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let name: string = "bamossza"; | |
name = 2; // เออเร่อเพราะว่าไม่ใช่ string | |
Error: cannot assign a `number` to a `string` | |
.. | |
// แต่หากเราแปลงให้เป็น JavaScript ก็จะได้แบบนี้ | |
.. | |
var name = "bamossza"; | |
name = 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let aString: string = 'Hi bamossza'; | |
let aNumber: number = '095504'; | |
let aBoolean: boolean = true or false; | |
let anArray: Array<string> = ['apple', 'banana']; | |
let anything1: any = 'a'; | |
let anything2: any = 1; | |
let anything3: any = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let anything: Array<any> = ['a', 'b', 1, 3, true]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum userStatus { | |
Active, | |
Inactive, | |
Block | |
} | |
.. | |
let status = userStatus.Active; | |
console.log(status); // Result: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum userStatus { | |
Active = 1, | |
Inactive, | |
Block, | |
} | |
จากโค้ดข้างบนจะได้ว่า Active = 1, Inactive = 2, Block = 3 | |
let status = userStatus.Active; | |
console.log(status); // Result: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setName(name: string): void { | |
this.name = name | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let eiei: void = undefined; | |
let eiei: void = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let student: [string, number] | |
student = ["bamossza", 1] | |
//แต่ถ้าแบบนี้ผิดเพราะว่าระบุค่าไม่ถูกต้องตามชนิดที่กำหนด | |
student = [1 , "bamossza"] // Type 'number' is not assignable to type 'string'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let aString: any = "bamossza"; | |
let length : number = (<string>aString).length; | |
console.log(length); // 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let aNumber: any = "5"; | |
let result : number = (<number>aNumber) + 6; | |
console.log(result); // 11 |
OlderNewer