classAnimal{}classCatextendsAnimal{meow(){console.log('cat meow');}}classDogextendsAnimal{wow(){console.log('dog wow');}}functiontest1(v:Cat):Cat {return v
}functiontest2(v:Animal):Animal {return v
}let a =test1(Animal)//报错let b =test2(Cat)//不报错
classAnimal{}classCatextendsAnimal{meow(){console.log('cat meow');}}classDogextendsAnimal{wow(){console.log('dog wow');}}classSmallDogextendsDog{public name :string='yehuozhili'}//参数dog,返回值DogtypetestType=(v:Dog)=>Dog
functionexec(v:testType){v(newSmallDog)}//试验:typechildToChild=(v:SmallDog)=>SmallDog
let aaaa :childToChild=(v)=>newSmallDogexec(aaaa)typechildToParent=(v:SmallDog)=>Animal
let aaaa2 :childToParent=(v)=>newAnimalexec(aaaa2)typeparentToChild=(v:Animal)=>SmallDog
let aaaa3:parentToChild=(v)=>newSmallDogexec(aaaa3)//不报错typeparentToParent=(v:Animal)=>Animal
let aaaa4:parentToParent=(v)=>newAnimalexec(aaaa4)
let aaaa :childToChild=(v)=>newSmallDogexec(aaaa)//不报错typechildToParent=(v:SmallDog)=>Animal
let aaaa2 :childToParent=(v)=>newAnimalexec(aaaa2)typeparentToChild=(v:Animal)=>SmallDog
let aaaa3:parentToChild=(v)=>newSmallDogexec(aaaa3)//不报错typeparentToParent=(v:Animal)=>Animal
let aaaa4:parentToParent=(v)=>newAnimalexec(aaaa4)