Skip to content

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

@vlad101vlad

Description

@vlad101vlad

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions