Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for branded keytypes in RecordType #107

Open
untio11 opened this issue Nov 18, 2024 · 0 comments
Open

Add support for branded keytypes in RecordType #107

untio11 opened this issue Nov 18, 2024 · 0 comments

Comments

@untio11
Copy link
Contributor

untio11 commented Nov 18, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant