Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/SincereCSL/Playgrounds
/ getPet
Function
getPet
TypeScript/StudyTypeScript/src/advanced_01.ts:33–38 ·
view source on GitHub ↗
(master: Master)
Source
from the content-addressed store, hash-verified
31
}
32
enum Master { Boy, Girl}
33
function
getPet(master: Master){
34
let
pet = master === Master.Boy ?
new
DogA() :
new
CatA();
35
pet.eat();
36
// pet.run();
37
return
pet
38
}
39
40
// 可区分的联合类型 (结合了联合类型和字面量类型保护方法)
41
Callers
nothing calls this directly
Calls
1
eat
Method · 0.65
Tested by
no test coverage detected