let size: number = 3
let list: number[] = [1, 2, 3]
let person: string = "Marco"
size = 'Polo' //Type 'string' is not assignable to type 'number'.
enum Color {Red = 1, Green, Blue}
let c: Color = Color.Green
let colorName: string = Color[2]
let foo: any
foo = 2
foo = 'Paris'
foo = [1, 2, 3]
let user: {
name: string,
age: number,
address: {
city: string,
country: string
}
}
user = { name: 'Marco', age: 20 } // Property 'address' is missing
let user: {
name: string,
age: number,
address?: {
city: string,
country: string
}
}
user = { name: 'Marco', age: 20 } // OK
interface User {
name: string
age: number
address: Address
}
interface Address {
city: string
country: string
}
let user: User
class Person {
title: string
protected name: string
private lastname: string
}
const user = new Person()
user.title = 'MR'
user.name = 'Rob' // Error
user.lastname = 'Willson' // Error
npm i typescript@next -g
tsc hello.ts