-
-
Notifications
You must be signed in to change notification settings - Fork 793
Open
Description
// Main data model schema
export const companySchema = Type.Object(
{
id: Type.Number(),
count: Type.String() //Stored as string in DB for example
},
{ $id: 'Company', additionalProperties: false }
)
// Schema for creating new entries
export const companyDataSchema = Type.Object(
{
text: Type.String(),
count: Type.Number() // Taken as number by API
},
{
$id: 'CompanyData',
additionalProperties: false
}
)
export type CompanyData = Static<typeof companyDataSchema>
//Type error - Type string is not assignable to type PromiseOrLiteral<number | undefined>
export const companyDataResolver = resolve<CompanyData, HookContext<CompanyService>>({
count: (value, obj, context, status) => {
return value + ' People'
}
})Similarly, if you have differing types between the main and create schema. context.result in hooks get's typed as any
create: [
async (context, next) => {
const result = context.result
// result is type any
await next()
}
]Types should never fallback into any if there is a unexpected type, the output type should be never so you don't accidentally break bypass TypeScript.
Metadata
Metadata
Assignees
Labels
No labels