如何使用 Temporal 作为类型?

问题描述 投票:0回答:1

当我尝试时:

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)
typescript date javascript-namespaces
1个回答
0
投票

Temporal
不是类型,而是命名空间。来自命名空间和模块

命名空间只是全局命名空间中命名的 JavaScript 对象。

或来自命名空间

“内部模块”现在是“命名空间”。 “外部模块”现在只是“模块”

要解决此问题,您需要使用正确的类型

Temporal.PlainDate

const a: Temporal.PlainDate = new Temporal.PlainDate(2024, 2, 1)
© www.soinside.com 2019 - 2024. All rights reserved.