Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

typescript generic dictionary

// You should check the source of why you have to force string and number
// Example 1 with Generic with default value

type DefaultSlotType = "something" | "something2"

type PlayerInventory<T extends  string | number = DefaultSlotType> = Record<T, InventorySlotSchema>

// Example 2 without default

type PlayerInventory<T extends  string | number> = Record<T, InventorySlotSchema>

// Example 2 without default and just a string
type PlayerInventory<T extends string> = Record<T, InventorySlotSchema>
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #typescript #generic #dictionary
ADD COMMENT
Topic
Name
1+3 =