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

Express server request parameters do not infer the correct type #31

Open
vlad101vlad opened this issue Jun 23, 2024 · 0 comments
Open

Comments

@vlad101vlad
Copy link

vlad101vlad commented Jun 23, 2024

In the course, during the part 3, section (a), "Fetching a single resource" - the routes that describe getting and deleting resources of notes

app.get('/api/notes/:id', (request, response) => {
 const id = request.params.id
 const note = notes.find(note => note.id === id)
 response.json(note)
})
image

This is flawed because the id is a string, but the id from the notes is a number. Thus, the code snippets have to be changed to explicitly make this cast of the parameter id:
const id = Number(request.params.id)

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

No branches or pull requests

1 participant