Skip to content

npx convex function-spec Reports incorrect literal #213

@dickermoshe

Description

@dickermoshe

The following task:

export const query10 = query({
  args: {
    i: v.literal(1),
  },
  returns: {
    i: v.literal(1),
  },
  handler: (ctx, args) => {
    return args;
  },
});

Will produce the following schema:

{
      "args": {
        "type": "object",
        "value": {
          "i": {
            "fieldType": {
              "type": "literal",
              "value": 1
            },
            "optional": false
          }
        }
      },
      "functionType": "Query",
      "identifier": "tasks.js:query10",
      "returns": {
        "type": "object",
        "value": {
          "i": {
            "fieldType": {
              "type": "literal",
              "value": 1
            },
            "optional": false
          }
        }
      },
      "visibility": {
        "kind": "public"
      }
    }

However this is incorrect.
The literal type should be 1.0.
This results in a crash at runtime:

ClientError.serverError(msg: [Request ID: 67be452c7b31cf99] Server Error
  ArgumentValidationError: `1` does not match literal validator `v.literal(1.0)`.Path: .i
  )

It's not enough just to copy the contents of the literal to the function-spec, we should really have another field called literalType for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions