当我尝试时:
const a: Temporal = new Temporal.PlainDate(2024, 2, 1)
我得到:
Cannot use namespace 'Temporal' as a type.deno-ts(2709)
会发生什么?这与
Date
的使用方式形成对比:
const b: Date = new Date(2024, 2, 1)
Temporal
不是类型,而是命名空间。来自命名空间和模块:
命名空间只是全局命名空间中命名的 JavaScript 对象。
或来自命名空间:
“内部模块”现在是“命名空间”。 “外部模块”现在只是“模块”
Temporal.PlainDate
:
const a: Temporal.PlainDate = new Temporal.PlainDate(2024, 2, 1)