Skip to content

Lint: sketchy-null-string: partially wrong error message? #4608

@stouf

Description

@stouf

The following code

'use strict';

// @flow

function sayHi(info: { name?: string }) {
  return `Hi ${info.name ? info.name : ''}!`;
}

sayHi({});
sayHi({ name: 'foo' });

with the following configuration

[ignore]

[include]

[libs]

[lints]
all=warn

[options]
include_warnings=true

gives me the following warning with Flow v0.52.0:

» flow
Warning: index.js:6
  6:   return `Hi ${info.name ? info.name : ''}!`;
                    ^^^^^^^^^ sketchy-null-string: Sketchy null check on string value. Perhaps you meant to check for null instead of for existence?
    6:   return `Hi ${info.name ? info.name : ''}!`;
                      ^^^^^^^^^ Potentially null/undefined value.
    6:   return `Hi ${info.name ? info.name : ''}!`;
                      ^^^^^^^^^ Potentially "" value.


Found 1 warning

Am I missing something? Flow seems to be confusing maybe type and optional property here doesn't it?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions