1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
interface Person { name: string }
const person: Person = { name: "xin" }
interface data { name: String } interface data { age: number }
let x: data = { name: "shunxin", age: 1 } console.log(x);
interface Person1 { name: string, age?: number } const person1: Person1 = { name: "xin" } console.log(person1);
interface Person2 { name: string, age?: number, [propName: string]: any }
const person2: Person2 = { name: "xin", age: 1, email: "123@qq.com" } console.log(person2);
interface Person3 { name: string, readonly age?: number, [propName: string]: any, } const person3: Person3 = { name: "xin", age: 1, } person3.age = 123; console.log(person3);
interface Person4 { name: string, readonly age?: number, [propName: string]: any, getName: () => void }
const person4: Person4 = { name: "xin", age: 1, getName: () => { console.log(person4.name); }, } person4.getName()
|