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

Migrate to v4 of the Node.js model for Azure Functions - TypeScript version please! #116285

Closed
johnnyreilly opened this issue Oct 21, 2023 · 5 comments

Comments

@johnnyreilly
Copy link
Contributor

johnnyreilly commented Oct 21, 2023

I tried to upgrade my function app to v4 of the Node.js model using TypeScript. I attempted to guess my way into doing this, but without success. Experienced errors like this:

Conversion of type '{ status: number; body: string; desc: any; ')': any; }' to type 'HttpResponse' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Type '{ status: number; body: string; desc: any; ')': any; }' is missing the following properties from type 'HttpResponse': headers, cookies, enableContentNegotiation, bodyUsed, and 5 more.ts(2352)

resulting from this code:

        return {
          status: 200,
          body: 'hello world',
        } as HttpResponse;

Maybe I've cracked it


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

@Naveenommi-MSFT
Copy link
Contributor

@johnnyreilly
Thank you for bringing this to our attention.
I've delegated this to content author @ggailey777, who will review it and offer their insightful opinions.

@johnnyreilly
Copy link
Contributor Author

Thanks - I think I've worked out how to do it myself now. I may blog about it. It'd be great if the official docs covered it too!

@johnnyreilly
Copy link
Contributor Author

johnnyreilly commented Oct 24, 2023

Here's my blog post on how to upgrade with TypeScript: https://johnnyreilly.com/migrating-azure-functions-node-js-v4-typescript

@ejizba
Copy link
Contributor

ejizba commented Jan 18, 2024

Hi @johnnyreilly I updated the docs to add a TypeScript pivot at the top of the article and made a few other tweaks based on your blog post (e.g. mentioning jsonBody). The changes might not show up in the docs until tomorrow, just fyi.

Thanks again for writing the blog post! I see a lot of value in these "real world" stories for both us and our users, especially compared to these official docs which are a bit more bland/generic

@johnnyreilly
Copy link
Contributor Author

Happy to help! And thanks for making the official docs even better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants