const arr: string = '123'
const arr2: number = 123
const arr3: boolean = true
const arrs: number[] = [1]
const arrs2: string[] = ['123']
const arrs3: Array<number> = [123]
const a: { user: string, name: string } = { user: '123', name: '小明' }
const b: { user: string, name?: number } = { user: '123' }
function mk(id: string | number) {
if (typeof id === 'string') {
console.log(id.toUpperCase());
} else {
console.log(id);
}
}
type user = { name: string, age: number }
const user2: user = { name: '小明', age: 18 }
const user3: user = { name: '小花', age: 10 }
function shows(message: any) {
console.log(message);
}
function abc(message: string): number {
return 123
}
const def: (age: number) => number = (age: number) => { return 123 }
interface student {
age: number,
sex?: string
}
interface student {
names: string
}
const student3: student = { age: 18, names: '123' }
type k = { name: string }
type m = k & { sge: number }
const kl: m = { name: '123', sge: 18 }
const kj: null = document.getElementById('#root') as null
const str: 'asd' = 'asd'
function getPosition(position: 'left' | 'right'): string {
return position
}
getPosition('left')
function request(url: string, methods: 'GET' | 'POST'): String {
return 'sending request'
}
const params: { url: string, methods: 'GET' | 'POST' } = { url: 'immoc.com', methods: 'POST' };
request(params.url, params.methods)
const f: null = null
const fs: undefined = undefined
function aaa(): void {
return
}