跳至主要內容

字面量推断 Literal Inference


字面量推断 Literal Inference

当变量初始化一个字面量对象时,对象的类型会被推断出来

08
08

解决:

type Method = "GET" | "POST"
declare function handleRequest(url: string, method: Method): void

const req = { url: "https://example.com", method: "GET" }

handleRequest(req.url, req.method as Method)
上次编辑于: 2024/3/20 20:52:35
贡献者: 52968