Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to annotation query type? #349

Closed
maicss opened this issue Mar 3, 2023 · 8 comments
Closed

How to annotation query type? #349

maicss opened this issue Mar 3, 2023 · 8 comments
Labels
enhancement New feature or request

Comments

@maicss
Copy link

maicss commented Mar 3, 2023

Environment

node : 18.12.1
nuxt: 3.0.0
h3: 1.0.2

Reproduction

export default defineEventHandler(async (event) => {
const { res } = event.node
const { code, name, someNumber } = getQuery(event)
})

Describe the bug

code, name, someNumber types are infer to string | QueryValue[] | null

How do I give types of them? Not where I use them with as assert.
like:

const handle Query = (code: string, name: string, index?: number) => {}
handleQuery (code as string, name as string, someNumber as number)

Additional context

No response

Logs

No response

@oleghalin
Copy link
Contributor

getQuery doesnt accept generic, so for now you can mark it as type using as construction

const query = getQuery(event) as Query;

@maicss
Copy link
Author

maicss commented Mar 3, 2023

OK, fine.
Will you consider getQuery<xxx>(event) ?

@maicss maicss closed this as completed Mar 3, 2023
@oleghalin
Copy link
Contributor

@pi0 is there any reason why getQuery doesnt accept generics? If no any problems with it i will be happy to contribute for this

@maicss
Copy link
Author

maicss commented Mar 3, 2023

It's sooo ugly, should unknow first.

const query = getQuery(event) as unknown as Query;

@oleghalin
Copy link
Contributor

oleghalin commented Mar 3, 2023

It's sooo ugly, should unknow first.

const query = getQuery(event) as unknown as Query;

I think as soon as Query implements Record<string, QueryValue | QueryValue[] > assigning it to getQuery is ok, but i can be wrong

@pi0
Copy link
Member

pi0 commented Mar 3, 2023

PR welcome to support generic type 🙏

@nozomuikuta nozomuikuta reopened this Mar 5, 2023
@nozomuikuta nozomuikuta added the enhancement New feature or request label Mar 5, 2023
@nozomuikuta
Copy link
Member

This issue can be fixed at 2 layers:

@pi0
Copy link
Member

pi0 commented Aug 1, 2023

ufo generic support released and h3 support landing via #417 in next release 🚀

@pi0 pi0 closed this as completed Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants