import { type } from 'arktype'
// Define the DTOs using ArkType
const dtos = {
create: type({
name: 'string',
data: 'unknown'
}),
read: type({
id: 'string'
}),
update: type({
id: 'string',
changes: 'object'
}),
delete: type({
id: 'string',
softDelete: 'boolean?'
})
} as const
// Infer the operation type from the DTO keys
type Operation = keyof typeof dtos
// Infer the DTO types from ArkType
type DTOMap = {
[K in Operation]: (typeof dtos)[K]['infer']
}
function performOperation<T extends Operation>(
op: T,
dto: DTOMap[T]
) {
switch (op) {
case 'create':
console.log(dto.) <--- how do i get arktype to infer that only the fields relevant to the create dto should be relevant here
case 'read':
case 'update':
case 'delete':
default:
}
}
import { type } from 'arktype'
// Define the DTOs using ArkType
const dtos = {
create: type({
name: 'string',
data: 'unknown'
}),
read: type({
id: 'string'
}),
update: type({
id: 'string',
changes: 'object'
}),
delete: type({
id: 'string',
softDelete: 'boolean?'
})
} as const
// Infer the operation type from the DTO keys
type Operation = keyof typeof dtos
// Infer the DTO types from ArkType
type DTOMap = {
[K in Operation]: (typeof dtos)[K]['infer']
}
function performOperation<T extends Operation>(
op: T,
dto: DTOMap[T]
) {
switch (op) {
case 'create':
console.log(dto.) <--- how do i get arktype to infer that only the fields relevant to the create dto should be relevant here
case 'read':
case 'update':
case 'delete':
default:
}
}