Skip to content

Nullable Types #6

@MarkHerhold

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?

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