Effect CommunityEC
Effect Community16mo ago
8 replies
James!

Handling Type Mismatch with Branded IDs in TypeScript

Hey all, I have a a schema and am using a branded ID:

export const AssetId = S.String.pipe(S.brand("AssetId"));
const CoreAsset = S.Struct({
  id: AssetId,
  name: AssetName,
  ...Metadata.fields,
});

export class Asset extends S.Class<Asset>("Asset")({
  ...CoreAsset.fields,
}) {}


I am querying my database using the TS Drizzle library which returns a typescript type of the database table. The returned string is NOT a branded AssetId.

return new Asset(assetReturnedFromDrizzle); However it throws the "string is not type of AssetId" which makes sense.

What is the proper way to handle this scenario?
image.png
Was this page helpful?