Create records without scopes #1187
-
I have a lot of records that have ids as their key. Those ids are template string like When trying to write a record with a type of my own as a record, the way I found was to use a scope : const arkUserSubscriptions = scope({
key: arkUserId,
value: arkUserSubscription,
record: {
'[key]': 'value',
},
}).export().record; And it produces the type I expect. It works. export function arkRecord<Key extends Type<string>, Value extends Type>(
key: Key,
value: Value
) {
return scope({
key,
value,
record: {
'[key]': 'value',
},
}).export().record;
}
const arkUserSubscriptions = arkRecord(arkUserId, arkUserSubscription); But it complains about Has anyone achieved that ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I have actually found a way, by using generics : import { generic } from 'arktype';
export const arkRecord = generic(
['Key', 'string'],
['Value', 'unknown']
)({
'[Key]': 'Value',
}); |
Beta Was this translation helpful? Give feedback.
-
There's actually a |
Beta Was this translation helpful? Give feedback.
I have actually found a way, by using generics :