Code Monkey home page Code Monkey logo

Comments (2)

arb avatar arb commented on June 12, 2024 2

I'm not a TypeScript expert or even active user so my ability to help with this will be very limited. My hunch is that, since this is a run-time conversation from string to integer, the TS compiler doesn't have a way to know that req.params.id has been changed to an integer. You may have to recast the value before calling f() I realize this isn't a great solution because now you're going to have to re-cast every result coming out of celebrate which is far from ideal.

One possible less-annoying path would be to create your own middleware that you'd insert right after celebrate calls. In there, you could either construct a new object and attach it to res.locals for example and then use that in the rest of the route. That way you could type it as needed. You could also recast req.* in there as well before calling next()

Hopefully someone can weigh in with a better idea than the one I've had.

Here-in lies the problem with trying to formally type a loosely typed language 😅

from celebrate.

stale avatar stale commented on June 12, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from celebrate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.