Encountered an issue, where typescript-is is unable to parse and produce a createEquals for the following type:
import { createEquals } from "typescript-is"
interface IBlogPost {
id: number;
title: string;
body: string;
}
interface IComment {
postId: number;
comment: string;
}
interface ITableTypes {
"BlogPosts": IBlogPost;
"BlogComments": IComment;
}
type IInsertRequest = {
[key in keyof ITableTypes]: {
command: "insert",
table: key,
value: ITableTypes[key]
}
}[keyof ITableTypes];
const isInsertRequest = createEquals<IInsertRequest>();
// Failed to transform node at ^^^^^^^^^^^^^^^^^^^
// Unbound type parameter, missing type node
Meantime, that type definition IInsertRequest doesn't trip up TS or VS Code:
// TypeScript is happy with the following object creations
// and can parse/type/intellisense them correctly
const request1: IInsertRequest = {
command: "insert",
table: "BlogPosts",
value: {
id: 1,
title: "title",
body: "body",
}
}
const request2: IInsertRequest = {
command: "insert",
table: "BlogComments",
value: {
postId: 1,
comment: "comment",
}
}
Appreciate your help taking a look at this. Is there something I'm doing wrong? Can I write this differently for it to compile and produce the appropriate equality function?
If curious, the way I'm intending to use that createEquals result is to take a random object (e.g. sent via API) and check to see if it's a valid insertion request (payload specifies a known table name and the corresponding value of the appropriate type for that table). Something like this:
function insert(request: any) { // coming from an http request, etc.
if (isInsertRequest(request)) {
const { table, value } = request;
// INSERT INTO {table} VALUES {value}
}
}
Love this library. Thank you!
Encountered an issue, where
typescript-is
is unable to parse and produce acreateEquals
for the following type:Meantime, that type definition
IInsertRequest
doesn't trip up TS or VS Code:Appreciate your help taking a look at this. Is there something I'm doing wrong? Can I write this differently for it to compile and produce the appropriate equality function?
If curious, the way I'm intending to use that
createEquals
result is to take a random object (e.g. sent via API) and check to see if it's a valid insertion request (payload specifies a known table name and the corresponding value of the appropriate type for that table). Something like this: