Skip to content

Add support for branded keytypes in RecordType #107

@untio11

Description

@untio11

PR #106 introduces a helper type that makes TS not forget the branding when defining a new record type. This is currently only applied to the value type of the record, as applying it to the key type breaks .literal() on records with branded keys:

type BrandedString = The<typeof BrandedString>;
const BrandedString = string.withBrand('BrandedString');

type BrandedKVRecord = The<typeof BrandedKVRecord>;
// Assuming this record remembers the branding on the keytype.
const BrandedKVRecord = record(BrandedString, BrandedString);
expectTypeOf(BrandedKVRecord.literal({
    a: 'b', // TS error: argument of type { a: string } not assignable to [...]
})).toEqual<Record<BrandedString, BrandedString>>();

This seems to be a problem stemming from DeepUnbranded<T> not properly dealing with the branded key type.

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