Destructure a function parameter in Typescript

0 votes

I'm trying to give a type to the members of below function. args is an object with a data property of type UserCreateInput

So, from this:

createUser(parent: any, args: any, context: any) {
    return context.prisma.createUser(args.data)
}

I wrote this:

createUser(parent: any, args: {data: UserCreateInput}, context: any) {
    return context.prisma.createUser(args.data)
}

I'm not sure how to replace 'xxx' in createUser(parent: any, xxx, context: any) so I can simply return return context.prisma.createUser(data)

Jun 8 in TypeSript by Logan
• 1,580 points
7 views

1 answer to this question.

0 votes

You can use the object de-structuring syntax:

createUser(parent: any, { data }: { data: UserCreateInput }, context: any) {
    return context.prisma.createUser(data)
}
answered Jun 9 by Nina
• 2,900 points

Related Questions In TypeSript

0 votes
1 answer

How to typecast a string to number in TypeScript?

You can use the parseInt or parseFloat functions, or simply use ...READ MORE

answered Jun 9 in TypeSript by Nina
• 2,900 points
7 views
0 votes
1 answer

How do I extend a TypeScript class definition in a separate definition file?

If you don't have control over the ...READ MORE

answered Jun 10 in TypeSript by Nina
• 2,900 points
14 views
0 votes
1 answer

How can I define a type for a CSS color in TypeScript?

There was a proposal for a type of ...READ MORE

answered Jun 15 in TypeSript by Nina
• 2,900 points
5 views
0 votes
1 answer

How to define props in TypeScript where a parent component injects props in its children?

Typescript doesn't remove this special rule "!text" ...READ MORE

answered Jun 16 in TypeSript by Nina
• 2,900 points
16 views
0 votes
2 answers

How can we pass a function as a parameter in java?

Java 8 and above Using Java 8+ lambda ...READ MORE

answered Aug 28, 2018 in Java by Daisy
• 8,120 points
382 views
0 votes
1 answer

Cannot access web3 object with typescript and ethereum

You still need to instantiate it first. ...READ MORE

answered Sep 25, 2018 in Blockchain by slayer
• 29,310 points
1,800 views
0 votes
1 answer

Using list comprehension how to call list of function

For the class method when used as ...READ MORE

answered Nov 14, 2018 in Python by Theodor
• 740 points
2,781 views
0 votes
1 answer

What is a name function in JavaScript & how to define it?

A named function declares a name as ...READ MORE

answered Mar 7, 2019 in Others by Frankie
• 9,830 points
776 views
0 votes
1 answer

How to declare and initialize a Dictionary in Typescript

Apparently this doesn't work when passing the ...READ MORE

answered May 31 in TypeSript by Nina
• 2,900 points
35 views
0 votes
1 answer

What is "not assignable to parameter of type never" error in TypeScript?

All you have to do is define ...READ MORE

answered May 31 in TypeSript by Nina
• 2,900 points
28 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP