Bracket Notation on Generics

Is there any way to do something like this? 🤔
scope({
BaseType: { entityType: "string" },
"Version<Entity extends BaseType, HashKeyPattern>": {
"...": "VersionCore & AiVersionFields",
data: "Entity",
HK: "HashKeyPattern",
SK: "StandardVersionSK",
EntityType: 'Entity["entityType"]',
},
})
scope({
BaseType: { entityType: "string" },
"Version<Entity extends BaseType, HashKeyPattern>": {
"...": "VersionCore & AiVersionFields",
data: "Entity",
HK: "HashKeyPattern",
SK: "StandardVersionSK",
EntityType: 'Entity["entityType"]',
},
})
No description
5 Replies
mailliW
mailliWOP4w ago
I think I will settle on passing in an extra generic property like this for now:
AiVersion<EntityType extends string, Entity, HashKeyPattern>": {
"...": "VersionCore & AiVersionFields",
data: "Entity",
HK: "HashKeyPattern",
SK: "StandardVersionSK",
entityType: "EntityType"
AiVersion<EntityType extends string, Entity, HashKeyPattern>": {
"...": "VersionCore & AiVersionFields",
data: "Entity",
HK: "HashKeyPattern",
SK: "StandardVersionSK",
entityType: "EntityType"
Would love to be able to drill down into types with bracket notation, but not sure how feasible that is given the usage of brackets for arrays. 🤷
LukeAbby
LukeAbby4w ago
You could always add a HKT for this it may already be built in It appears not
LukeAbby
LukeAbby4w ago
ArkType
ArkType Docs
TypeScript's 1:1 validator, optimized from editor to runtime
LukeAbby
LukeAbby4w ago
You could add a HKT like Get<EntityType, 'key'>
mailliW
mailliWOP4w ago
Nice.. didn't think of that. Tyty 🙏

Did you find this page helpful?