I'm new to TypeScript and not sure how to handle this. I'm using PostGraphile to generate my schema and Relay to generate graphql types. My Post
table has createdAt and updatedAt fields which are 'timestamp without timezone' data type. Relay is generating this and I'm not sure why:
export type Post_post = {
// why doesn't Relay identify these as type Date?
...
readonly createdAt: unknown | null;
readonly updatedAt: unknown | null;
};
My problem is when trying to use that 'unknown' date like this: const ca: any = new Date(createdAt);
I get this:
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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…