D
D
Denioo2021-07-05 14:47:48
Node.js
Denioo, 2021-07-05 14:47:48

How to set global @types in Koa?

Hello everyone, the problem is that in koa when you connect typescript and write let's say

router.get('/', async (ctx: Context): Promise<void> => {
  const { id }: string = ctx.query;
}

Further in the code, this id will be highlighted, but if you put the type any instead of string, then everything will be ok, but how to avoid this? As an option, it seems like you need to make a @types folder and throw the interface there, but I can’t find any information about this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-07-05
@Denioo

Well, not right, you are trying to assign a type to an stringobject of the form .{id: some}
const { id }: {id: string}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question