typescript - 带有 Typescript 的 Luxon:TS2339:“DateTime”类型上不存在属性“c”
问题描述
我一直在尝试将 JS 函数转换为 TS,我在其中使用Luxon。
问题是,当我尝试从now()c
访问该属性时,出现以下错误Typescript: TS2339: Property 'c' does not exist on type 'DateTime'.
import { DateTime as Luxon } from 'luxon';
const getCurrentHour = (): number => {
const dTime = Luxon.now();
return dTime.c.hour;
}
console.log(typeof Luxon.now()); // I get "DateTime"
console.log(Luxon.now()); // I can see the "c" property
我知道 JavaScript 的 DateTime 接口没有这个c
属性,但是我如何设法用 Luxon 和 TypeScript 编写这个代码呢?我已经安装了@types/luxon并试图在那里找到一个类型导出,但没有成功。
解决方案
我有同样的问题。尝试return dTime.hour
代替return dTime.c.hour
推荐阅读
- corda - 关闭网络上的 Corda 节点的推荐方法是什么?
- python-3.x - 无法弄清楚 mongoengine 上的许多更新
- css - css中的boostrap焦点输入和图标
- ios - 自定义 UITableViewCell 中的 LayoutSubviews() 不适用于所有重用的单元格
- javascript - JavaScript 正则表达式匹配查询参数但不匹配 HTML 实体
- python - 如何创建一个简单的子程序来查找和打印用户输入的年龄?
- android - 如何在后台运行我的应用程序并收听来自其他应用程序或浏览器的超链接点击事件
- conda - 从 Nipype docker 镜像 CommandNotFound 构建 Singularity 配方
- python - Python日期填补空白,熊猫数据框
- c# - Dapper 可以在返回中处理空值吗?