Skip to content

Mongo TS field.temporal.timestamp(undefined, 'now') types both phases as optional #30466

Open

Description

@wmadden-electric

What a user sees. In the Mongo TypeScript builder, field.temporal.timestamp() and field.temporal.timestamp('now', 'now') get exact types. field.temporal.timestamp(undefined, 'now') does not: TypeScript widens both option arguments to "the option or undefined", so the field's type says both onCreate and onUpdate are optional. The onUpdate default the user asked for is typed as maybe absent, and the create and update input types are less precise than for the other two forms.

Where. The phase-template typing in packages/2-mongo-family/2-authoring/contract-ts/src/contract-builder.ts (the doc comment above the phase template describes the widening); pinned as current behaviour in packages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.execution-defaults.test-d.ts.

Likely fix. Give the TypeScript form named-object arguments, field.temporal.timestamp({ onUpdate: 'now' }), which TypeScript infers exactly, and check what the SQL TypeScript temporal.timestamp signature does so both families take the same shape.

Where it came from. #30403.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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