forked from palantir/tslint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Await promise configurable (palantir#2705)
- Loading branch information
Showing
8 changed files
with
167 additions
and
52 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
class CustomPromise<T> {} | ||
|
||
async function fAny() { | ||
const isAny: any = 1; | ||
|
||
// any type | ||
await isAny; | ||
|
||
// union type with any type | ||
await (Math.random() > 0.5 ? isAny : 0); | ||
} | ||
|
||
async function fNonPromise() { | ||
// number type | ||
await 0; | ||
~~~~~~~ [0] | ||
|
||
// union type without Promise | ||
await (Math.random() > 0.5 ? "" : 0); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] | ||
|
||
// non Promise type | ||
class NonPromise extends Array {} | ||
await new NonPromise(); | ||
~~~~~~~~~~~~~~~~~~~~~~ [0] | ||
} | ||
|
||
async function fStandardPromise() { | ||
// direct type | ||
const numberPromise: Promise<number>; | ||
await numberPromise; | ||
|
||
// 1st level base type | ||
class Foo extends Promise<number> {} | ||
const foo: Foo = Foo.resolve(2); | ||
await foo; | ||
|
||
// 2nd level base type | ||
class Bar extends Foo {} | ||
const bar: Bar = Bar.resolve(2); | ||
await bar; | ||
|
||
// union type | ||
await (Math.random() > 0.5 ? numberPromise : 0); | ||
await (Math.random() > 0.5 ? foo : 0); | ||
await (Math.random() > 0.5 ? bar : 0); | ||
} | ||
|
||
async function fCustomPromise() { | ||
// direct type | ||
const numberPromise: CustomPromise<number>; | ||
await numberPromise; | ||
|
||
// 1st level base type | ||
class Foo extends CustomPromise<number> {} | ||
const foo: Foo = Foo.resolve(2); | ||
await foo; | ||
|
||
// 2nd level base type | ||
class Bar extends Foo {} | ||
const bar: Bar = Bar.resolve(2); | ||
await bar; | ||
|
||
// union type | ||
await (Math.random() > 0.5 ? numberPromise : 0); | ||
await (Math.random() > 0.5 ? foo : 0); | ||
await (Math.random() > 0.5 ? bar : 0); | ||
} | ||
|
||
[0]: 'await' of non-Promise. |
File renamed without changes.
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,8 @@ | ||
{ | ||
"linterOptions": { | ||
"typeCheck": true | ||
}, | ||
"rules": { | ||
"await-promise": [true, "CustomPromise"] | ||
} | ||
} |
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,47 @@ | ||
async function fAny() { | ||
const isAny: any = 1; | ||
|
||
// any type | ||
await isAny; | ||
|
||
// union type with any type | ||
await (Math.random() > 0.5 ? isAny : 0); | ||
} | ||
|
||
async function fNonPromise() { | ||
// number type | ||
await 0; | ||
~~~~~~~ [0] | ||
|
||
// union type without Promise | ||
await (Math.random() > 0.5 ? "" : 0); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] | ||
|
||
// non Promise type | ||
class NonPromise extends Array {} | ||
await new NonPromise(); | ||
~~~~~~~~~~~~~~~~~~~~~~ [0] | ||
} | ||
|
||
async function fPromise() { | ||
// direct type | ||
const numberPromise: Promise<number>; | ||
await numberPromise; | ||
|
||
// 1st level base type | ||
class Foo extends Promise<number> {} | ||
const foo: Foo = Foo.resolve(2); | ||
await foo; | ||
|
||
// 2nd level base type | ||
class Bar extends Foo {} | ||
const bar: Bar = Bar.resolve(2); | ||
await bar; | ||
|
||
// union type | ||
await (Math.random() > 0.5 ? numberPromise : 0); | ||
await (Math.random() > 0.5 ? foo : 0); | ||
await (Math.random() > 0.5 ? bar : 0); | ||
} | ||
|
||
[0]: 'await' of non-Promise. |
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": { | ||
"target": "es6" | ||
} | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.