Overview

An interface which allows you to extend the types of SomeId to include your own custom types via declaration merging.

⚠️Warning: This is an advanced feature, and should only be used if you really need to use a type for the _id field which isn't present in SomeId for whatever reason.

To use this, you may merge the SomeIdTypes interface into your own project to specify additional allowed types for document IDs.

  • This is especially useful if your system uses custom scalar representations (e.g. branded types or custom datatypes) that are not part of the default set.

The field may be called anything except for baseTypes, as that is reserved for the default types.

✏️Note: This is a global declaration merging, so you should only do this once in your project.


Examples

In this example after declaration merging, the SomeId will now also accept { $uuid: string } and BigNumber as valid values for _id.

Example

import { BigNumber, SomeId } from '@datastax/astra-db-ts';

declare module '@datastax/astra-db-ts' {
interface SomeIdTypes {
myTypes: { $uuid: string } | BigNumber,
}
}

const id1: SomeId = { $uuid: '123e4567-e89b-12d3-a456-426614174000' }; // OK
const id2: SomeId = BigNumber(123456789); // OK
const id3: SomeId = { $car: 123 }; // Type Error

In this example, SomeId will be set to any.

Example

import { SomeId } from '@datastax/astra-db-ts';

declare module '@datastax/astra-db-ts' {
interface SomeIdTypes {
myTypes: any,
}
}

const id1: SomeId = { $uuid: '123e4567-e89b-12d3-a456-426614174000' }; // OK
const id2: SomeId = BigNumber(123456789); // OK
const id3: SomeId = { $car: 123 }; // OK

See

SomeId

interface SomeIdTypes {
    baseTypes: null | string | number | bigint | boolean | UUID | ObjectId | Date;
}

Properties

Properties

baseTypes: null | string | number | bigint | boolean | UUID | ObjectId | Date