Type alias CqlType2TSType<Def, Overrides>

CqlType2TSType<Def, Overrides>: CqlType2TSTypeInternal<PickCqlType<Def>, Def, Overrides>
Overview

Converts a CQL type to its TS equivalent.

This interprets both StrictCreateTableColumnDefinition and LooseCreateTableColumnDefinition equally.

  • Though note that the former type must be used for collection/vector types

Type Parameters

Example

// number | null
CqlType2TSType<'int', ...>

// DataAPIDuration | null
CqlType2TSType<{ type: 'duration }, ...>

// Map<string, number>
CqlType2TSType<{ type: 'map', keyType: 'text', valueType: 'int' }>

// unknown
CqlType2TSType<'idk', ...>

// TypeErr<`Invalid definition for 'map'; should be of format { ... }`>
CqlType2TSType<'map'>
Getting rid of the | null

As this type is intended primarily for internal usage within the InferTableSchema-like types, it will return <type> | null for all scalar values, as they all may be null when returned back from the Data API

  • Collection types are excluded from this rule as, when returned from the Data API, they will just be set to their empty value.

You can simply do CqlType2TSType<...> & {} to get rid of the | null type (or use type overrides as explained below).

Type overrides

When working with custom ser/des, you may find it necessary to override the type of a specific datatype.

See TableSchemaTypeOverrides for more information on this subject.

Example

// BigNumber | null
CqlType2TSType<'bigint', { bigint: BigNumber | null }>

See

InferTableSchema