#how can I solve Spread types may only be created from object types???
17 messages · Page 1 of 1 (latest)
My code:
`@Patch('/features/:featureType')
async updateFeature(@Req() req: Request, @Param('guild') guild: string, @Body() body: Partial<':featureBod'>, @Param('featureType') featureType: string, @Param('featureBod') featureBod: string) {
this.guilds.checkPermissions(auth(req), guild);
if (featureType === 'welcome-message') {
featureBod === 'WelcomeMessage'
const updated = await this.prisma.welcomeMessage.update({
where: {
id: guild,
},
data: {
...body,
id: undefined,
},
});
return updated;
} else if (featureType === 'utility') {
featureBod === 'Utility'
const updated = await this.prisma.utility.update({
where: {
id: guild,
},
data: {
...body,
id: undefined,
},
});
return updated;
}
}`
Error: error TS2698: Spread types may only be created from object types.
how can I solve Spread types may only be created from object types.???
how can I solve Spread types may only be created from object types???
!helper
:warning: Please wait a bit longer. You can ping helpers <t:1694998561:R>.
@latent crest please help me
you're using Partial on a string... which is just a string
@carmine gate What should I do instead of a string?
@Param('featureBod') featureBod: string
what happen if you do any?
@hasty olive It's still the same error and I don't know the exact reason
you should create a separate DTO for that. from the docs A DTO is an object that defines how the data will be sent over the network. We could determine the DTO schema by using TypeScript interfaces, or by simple classes.
Please can you send me an example of the code@hasty olive
// sample.dto.ts
export class SampleDto {
name: string;
age: number;
breed: string;
}
@Body() sampleDto: SampleDto
This is the first time I deal with such a file. Can you explain it to me more please?