A
arktype2mo ago
Dimava

`scope.validate` for a scope with imports

The usage of type.validate with custom existing scopes is straightforward - just use type.validate<def, scope.t> However, how do I validate a new scope definition with existing imports/exports?
import { scope, type } from 'arktype'

const baseScope = scope({
'id': 'string'
})
type $ = typeof baseScope.t

function myType<const def>(def: type.validate<def, $>): type.infer<def, $> {
return baseScope.type(def)
}
myType({ x: 'id' })

function myScopeWithExport<const def>(def: scope.validate<def>): scope.infer<def> {
return scope({
...baseScope.export(),
...def
} as any) as any
}
myScopeWithExport({ x: 'id' })

function myScopeWithImport<const def>(def: scope.validate<def>): scope.infer<def> {
return scope({
...baseScope.import(),
...def
} as any) as any
}
myScopeWithImport({ x: 'id' })
import { scope, type } from 'arktype'

const baseScope = scope({
'id': 'string'
})
type $ = typeof baseScope.t

function myType<const def>(def: type.validate<def, $>): type.infer<def, $> {
return baseScope.type(def)
}
myType({ x: 'id' })

function myScopeWithExport<const def>(def: scope.validate<def>): scope.infer<def> {
return scope({
...baseScope.export(),
...def
} as any) as any
}
myScopeWithExport({ x: 'id' })

function myScopeWithImport<const def>(def: scope.validate<def>): scope.infer<def> {
return scope({
...baseScope.import(),
...def
} as any) as any
}
myScopeWithImport({ x: 'id' })
1 Reply
Dimava
DimavaOP2mo ago
I'd like scope.validate/scope.infer to have the second argument the same way type.validate/type.infer has Then the user can put scope.imports()/scope.exports()there @ssalbdivad
Want results from more Discord servers?
Add your server