-
Notifications
You must be signed in to change notification settings - Fork 887
Conversation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [F] | ||
|
||
get<number | undefined>() === undefined; | ||
get<string | undefined>() == null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this rule also check for non strict comparisons to null
or undefined
if only one of them is possible?
Example:
get<string|undefined>() == null;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [use === undefined instead]
get<string|undefined|null>() == null; // still allowed
get<string | undefined>() == null; | ||
get<string | null>() == undefined; | ||
get<string | null>() == null; | ||
get<string | undefined>() == undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here the rule could suggest to use strict equality comparison
get<string | undefined>() == null; | ||
get<string | null>() == undefined; | ||
get<string | null>() == null; | ||
get<string | undefined>() == undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test for the following:
get<null|undefined> == null;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [T]
get<null|undefined> != undefined;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [F]
@@ -0,0 +1,210 @@ | |||
/** | |||
* @license | |||
* Copyright 2016 Palantir Technologies, Inc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2017
@@ -178,6 +178,11 @@ export function isTypeFlagSet(type: ts.Type, flagToCheck: ts.TypeFlags): boolean | |||
/* tslint:enable:no-bitwise */ | |||
} | |||
|
|||
/** Type predicate to test for a union type. */ | |||
export function isUnionType(type: ts.Type): type is ts.UnionType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utils
shouldn't be cluttered with wrappers for isTypeFlagSet
2c491e0
to
c263f8c
Compare
Would this rule make |
@andy-hanson if it catches typos like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andy-hanson lgtm
sorry, can you merge with master? |
b78a139
to
c57cbf4
Compare
PR checklist
What changes did you make?
Added the
strict-type-predicates
rule, which warns fortypeof x === "string"
wherex
is always (or never) a string, and forx === undefined
wherex
is always (or never)undefined
.Is there anything you'd like reviewers to focus on?
Can't do
instanceof
checks yet as the type checker does not expose assignability checks. If it did, thegetTypePredicateForKind
function could be removed.