Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unbound type parameter, missing type node. #95

Open
ArashMotamedi opened this issue Mar 22, 2021 · 0 comments
Open

Unbound type parameter, missing type node. #95

ArashMotamedi opened this issue Mar 22, 2021 · 0 comments

Comments

@ArashMotamedi
Copy link

ArashMotamedi commented Mar 22, 2021

Love this library. Thank you!

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}
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant