function fn():string{
return 'string'
}
fn()
function getInfo(name:string,age:number):string{
return `${name} -- ${age}`
}
getInfo('bobo',18)
function c(name:string,age?:number){
return age? `${name} -- ${age}` : `${name} -- 年龄保密`
}
fn('bobo',18)
function fn(o:{prop:number}){
o.prop
}
fn({prop:0})
//等同于
type Prop = {prop:number} & {foo:string}
function fn(o:Prop){}
//type和interface的区别(基本上完全相同 )
interface Prop{
prop:number
}
//场景主要源码和框架,函数用参个数、类型或者返回值类型区分同名函数
function watch(tar:() => void):void;
function watch(tar:() => void,flag:(v1:any,v2:any) => void):void;
//实现
function watch(tar:()=>void,flag:(v1:any,v2:any) => void){
if(tar && flag){
console.log(1)
}else{
console.log(2)
}
}
watch()
watch()
网友评论