How do I type ast
?
import { CustomScalar, Scalar } from '@nestjs/graphql'
import { Kind } from 'graphql'
export class DateScalar implements CustomScalar<number, Date> {
description = 'Date custom scalar type'
parseValue(value: number): Date {
return new Date(value) // value from the client
}
serialize(value: Date): number {
return value.getTime() // value sent to the client
}
parseLiteral(ast): Date { // <-- ???
if (ast.kind === Kind.INT) {
return new Date(ast.value)
}
return null
}
}
I tried to use
interface AST {
kind: string
value: number
}
but then I do get the error
Property 'parseLiteral' in type 'DateScalar' is not assignable to the same property in base type 'CustomScalar<number, Date>'.
Type '(ast: AST) => Date' is not assignable to type 'GraphQLScalarLiteralParser<Date>'.
Types of parameters 'ast' and 'valueNode' are incompatible.
Type 'ValueNode' is not assignable to type 'AST'.
Property 'value' is missing in type 'VariableNode' but required in type 'AST'
question from:
https://stackoverflow.com/questions/65644162/how-do-i-type-parseliteral-parameter-in-date-scalar 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…