Closed desudo closed 4 months ago
Pattern matching for keys like the above is not possible in TypeScript which is why it can't resolve to a known type.
Yes, that is correct.
Even if I use a genuine property, queryProperty
still does not resolve as you can see in the screenshot.
When using queryProperty
by itself, it does work out just fine:
I'm sorry if my initial example confused you.
Looks like it's one of the odd and mysterious TypeScript quirks. This appears to work:
import { JSONSchema } from 'json-schema-to-ts'
import { PropertyQuery, schema, Infer } from '@feathersjs/schema'
const queryPropertyWrapper = <T extends JSONSchema>(schema: T) => schema as PropertyQuery<T, unknown>
const testSchema = schema({
$id: 'something',
type: 'object',
properties: {
name: queryPropertyWrapper({ type: 'string' })
}
} as const)
type Test = Infer<typeof testSchema>
This helped quite a lot. Thank you for your patience and time :)
The schema is resolving into type unknown or any when using queryProperty from
@feathers/schema
.mytest
would resolve in the structure I intend to have,Schema
does not.I also have a working example, on Stackblitz: Example
Additional Information:
NodeJs: v16.20.2 npm: v8.19.4 TypeScript: v5.3.3 @feathers/schema: 5.0.14
Thanks for any help!