Skip to content

Make Node type more specific when referencing them from other types?Β #143

@jens-f

Description

@jens-f

Would it be possible to narrow down the type-definitions of interface fields to reference more specific types instead of using Node?
I've been checking out the type definitions of this fork https://github.com/pg-nano/pg-parser/ and the more specific autogenerated types really help when writing code that processes the AST.

For example, comparing the type definition https://github.com/launchql/libpg-query-node/blob/main/types/16/src/types.ts#L1239-L1245

export interface DefElem {
    defnamespace?: string;
    defname?: string;
    arg?: Node;
    defaction?: DefElemAction;
    location?: number;
}

and the same definition from https://github.com/pg-nano/pg-parser/blob/16-latest/src/lib/ast.ts#L1974-L1993

export type DefElem = {
    /** NULL if unqualified name */
    defnamespace?: string;
    defname: string;
    /** typically Integer, Float, String, or
     * TypeName */
    arg?: {
        A_Const: A_Const;
    } | {
        Boolean: Boolean;
    } | {
        Float: Float;
    } | {
        Integer: Integer;
    } | {
        List: List;
    } | {
        String: String;
    } | {
        TypeName: TypeName;
    } | {
        VariableSetStmt: VariableSetStmt;
    };
    /** unspecified action, or SET/ADD/DROP */
    defaction: DefElemAction;
    /** token location, or -1 if unknown */
    location?: number;
};

It's much more obvious what cases to cover when processing the arg entry in the DefElem AST node. I usually take a couple of sample ASTs to learn what the typical arg Nodes might be and then build the processing functionality around it but if the list of possible node types was already specified upfront that be super helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions