Skip to content

Nullable Types #6

Description

@MarkHerhold

I am running into an issue that makes it hard to use nullable types. For instance, a table could have an auto-generated ID (UUID or sequential number) and I'd try to match that with a nullable property on an interface: id?: string.

TS error:

Property 'id' of type 'string | undefined' is not assignable to string index type 'RDSDataParameterValue'.

Code:

import { RDSDataParameters } from 'rds-data/lib/RDSData';

export interface Message extends RDSDataParameters {
    id?: string; // error here
    message: string;
}

const m: Message = { message: "hi" };

const { data } = await db.query(
  `INSERT INTO messages(message)
  VALUES(:message)
  RETURNING *`,
  m,
);

What is the recommended approach here?

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions