我是 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