This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 887
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix strict-type-predicate for unknown (#4444)
* Add tests for strict-type-predicates and unknown * Fix unknown with strict-type-predicate * Fix unknown literal
- Loading branch information
1 parent
8de3b91
commit c054cbb
Showing
5 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[typescript]: >= 3.0.0 | ||
|
||
declare function get<T>(): T; | ||
|
||
// typeof | ||
{ | ||
typeof get<unknown>() === "undefined"; | ||
typeof get<unknown>() === "boolean"; | ||
typeof get<unknown>() === "number"; | ||
typeof get<unknown>() === "string"; | ||
typeof get<unknown>() === "symbol"; | ||
typeof get<unknown>() === "function"; | ||
typeof get<unknown>() === "object"; | ||
} | ||
|
||
// negation | ||
{ | ||
get<unknown>() !== null; | ||
get<unknown>() !== undefined; | ||
} | ||
|
||
// reverse left/right | ||
{ | ||
"string" === typeof get<unknown>(); | ||
|
||
undefined === get<unknown>(); | ||
} | ||
|
||
// type parameters | ||
{ | ||
function f<T>(t: T) { | ||
typeof t === "boolean"; | ||
} | ||
} | ||
|
||
const body: unknown = 'test'; | ||
if (typeof body === 'object') | ||
console.log('a'); | ||
|
||
let test: unknown = undefined; | ||
if (test !== undefined) | ||
console.log('b'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"compilerOptions": { | ||
"strictNullChecks": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"strict-type-predicates": true | ||
} | ||
} |