beamable-sdk / contents/types / ContentTypeFromId
Type Alias: ContentTypeFromId<Id>¶
ContentTypeFromId<
Id> =Idextends keyofContentTypeMap?ContentTypeMap[Id] :ExtractPrefixes<Id> extends infer Prefixes ?Prefixesextends keyofContentTypeMap?ContentTypeMap[Prefixes] :ContentBase:ContentBase
Defined in: src/contents/types/ContentTypeFromId.ts:40
Derives the most specific TypeScript type for a given content ID.
This utility searches for a type by first attempting an exact match on the ID.
If no direct match is found, it falls back to checking the parent ID
(the string with its last segment removed). If no match is found, it defaults
to the base ContentBase type.
Type Parameters¶
Id¶
Id extends string
The dot-delimited content identifier.
Example¶
// Assuming ContentTypeMap contains:
// "items": ItemContent
// "items.shield": ShieldContent
// "items.shield.wooden": WoodenShieldContent
type T1 = ContentTypeFromId<"items.shield.wooden.rare">; // -> WoodenShieldContent
type T2 = ContentTypeFromId<"items.shield.metal">; // -> ShieldContent
type T3 = ContentTypeFromId<"items.weapon">; // -> ItemContent
type T4 = ContentTypeFromId<"unknown.type">; // -> ContentBase