首页 / typescript / Know How to Tell Whether a Symbol Is in the Type Space or Value Space
A symbol in TypeScript exists in one of two spaces:
function email(to: Person, subject: string, body: string): Response {
// ――――― ――――― ――――――― ―――― Values
// ―――――― ―――――― ―――――― ―――――――― Types
}
There are many other constructs that have different meanings in the two spaces:
In value space, & and | are bitwise AND and OR. In type space they are the intersection and union operators. |
Correct
function email(options: {to: Person, subject: string, body: string}) {
// ...
}
function email(
{to, subject, body}: {to: Person, subject: string, body: string}
) {
// ...
}
ERROR
function email({
to: Person,
// ~~~~~~ Binding element 'Person' implicitly has an 'any' type
subject: string,
// ~~~~~~ Binding element 'string' implicitly has an 'any' type
body: string
// ~~~~~~ Binding element 'string' implicitly has an 'any' type
}) { /* ... */ }