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

fix: Don't forget branding in value type of Record. #106

Open
wants to merge 4 commits into
base: next
Choose a base branch
from

Conversation

untio11
Copy link
Contributor

@untio11 untio11 commented Nov 18, 2024

Before this fix, branding information was lost design time on the key and value types of a Record type:

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

type BrandedKVRecord = The<typeof BrandedKVRecord>;
const BrandedKVRecord = record(BrandedString, BrandedString);

// Old behaviour:
expectTypeOf<BrandedKVRecord>().toEqualTypeOf<Record<string, string>>();

// New behaviour:
expectTypeOf<BrandedKVRecord>().toEqualTypeOf<Record<string, BrandedString>>();

This same helper type (Unwidened<T>) can be used on the key type too, however, this breaks compatibility with .literal() because DeepUnbranded<T> can't really deal with branded key types yet.

@untio11 untio11 force-pushed the robin/partial-fix-record-type-branding branch from 801c630 to a8e3231 Compare November 18, 2024 16:04
@untio11 untio11 force-pushed the robin/partial-fix-record-type-branding branch 2 times, most recently from 75caf44 to 4040b6e Compare November 18, 2024 16:10
@untio11 untio11 force-pushed the robin/partial-fix-record-type-branding branch from 4040b6e to 2888f0f Compare November 18, 2024 17:07
@untio11 untio11 force-pushed the robin/partial-fix-record-type-branding branch from 88bd670 to 78a2882 Compare November 18, 2024 17:15
@untio11 untio11 changed the title fix: Introduce small helper type that prompts TS to not forget branding. fix: Don't forget branding in value type of Record. Nov 18, 2024
@untio11 untio11 marked this pull request as ready for review November 18, 2024 17:25
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

Successfully merging this pull request may close these issues.

1 participant