“未知”类型不能分配给“日期”类型

问题描述

我是 TypeScript 的新手,不确定如何处理。我正在使用 PostGraphile 生成我的模式和 Relay 来生成 graphql 类型。我的 Post 表具有 createdAt 和 updatedAt 字段,它们是“没有时区的时间戳”数据类型。 Relay 正在生成这个,我不知道为什么:

export type Post_post = {
  // why doesn't Relay identify these as type Date?
  ...
  readonly createdAt: unknown | null;
  readonly updatedAt: unknown | null;
};

我的问题是在尝试使用这样的“未知”日期时:const ca: any = new Date(createdAt); 我明白了:

No overload matches this call.
  Overload 1 of 4,'(value: string | number | Date): Date',gave the following error.
    Argument of type 'unknown' is not assignable to parameter of type 'string | number | Date'.
      Type 'unknown' is not assignable to type 'Date'.
  Overload 2 of 4,'(value: ReactText): Date',gave the following error.
    Argument of type 'unknown' is not assignable to parameter of type 'ReactText'.
      Type 'unknown' is not assignable to type 'number'.  TS2769

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...