Skip to content

JavaScript warnings on Array, Object-type methods does not respect function parameter defaults #73

Open
@mschlitz-trux

Description

@mschlitz-trux

Using this example code below:

_renderAttachments(attachments = []) {
    return attachments.map((attach) => {

DeepCode will warn that calling .map() on non array object for attachments will not work.
It suggests to use (attachments || []). While this is correct, it does not account for the function parameter default value which is already provided.

In the above case, the function already provides a fallback for (attachments = []), so the suggested change would offer no further benefit.

This also occurs for things like Object fallbacks (attachments = {}), or es6 Object types such as (attachments = new Map())

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