-
Notifications
You must be signed in to change notification settings - Fork 661
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,52 @@ | ||
// tslint:disable:no-unused-expression | ||
import { WebClient } from '@slack/web-api'; | ||
import { WebClient, WebAPICallResult } from '@slack/web-api'; | ||
|
||
const web = new WebClient(); | ||
|
||
/* Testing the return type of WebClient#paginate() */ | ||
|
||
// $ExpectType AsyncIterator<WebAPICallResult> | ||
web.paginate('conversations.list'); | ||
/** | ||
* SO, for all intents and purpurposes, this thing below is just an AsyncIterator. That's what it's meant to be. "So why | ||
* not just put `AsyncIterator`," you ask. Good question. Let me tell you a tale: | ||
* | ||
* Back in the year 2019, all was happy and cheerful. These integration tests $ExpectedType AsyncIterator and this | ||
* rendundant interface was naught. Birds chirped with glee and children played in the fields. Nothing could possibly | ||
* go wrong. | ||
* | ||
* Then something went wrong. From every cardinal direction a storm approached, its winds ripping trees from their roots | ||
* and hatchlings from their mothers. Merciless, the strom tore apart the field and everything it supported. | ||
* | ||
* We never forget this storm. We keep its bittersweet memory in our hearts. We say its name only when it is needed: | ||
* `[email protected]`. | ||
* | ||
* For, you see, this was not your average storm. No, this storm approached instead as something to be celebrated, with | ||
* its updated generator types and better iterator ergonomics. Alas, in heindsight this was but a mirage--a trojan | ||
* horse, even--masquerading the terror that followed. | ||
* | ||
* It struck right at the edge: the integration tests. For, you see, their foundation is dtslint, which (at the time of | ||
* the storm) tests against each minor release of TypeScript from 2.0 all the way to `typescript@next`. But, you see, | ||
* this storm brought about changes in that last version. It changed the type of `AsyncIterable`, adding two new type | ||
* arguments with defaults. Whilst usage remain unaffected, the same could not be said of our types integration tests-- | ||
* for these tests were now failing. | ||
* | ||
* Our most trustworthy guard, Travis (CI), attempted to warn us of the dangerous storm, but by the time the message | ||
* reached us the damage was done: builds were failing, PRs were reported as failing, and builds in general were a sea | ||
* of red ✗ (read: sea of blood). | ||
* | ||
* This is why we've enacted this memorial: the __DangerouslyOutmodedAsyncIteratorSignatureWrapper. Its purpose is not | ||
* only to remember the sorrows of past maintiners, but to also appease the storm by wrapping `AsyncIterator` in a new | ||
* type that is fully equivalent, yet named different under `$ExpectType` (that is, the same across TypeScript | ||
* versions). | ||
*/ | ||
interface __DangerouslyOutmodedAsyncIteratorSignatureWrapper<T> extends AsyncIterator<T> { | ||
// oh no | ||
} | ||
|
||
// $ExpectType AsyncIterator<WebAPICallResult> | ||
web.paginate('conversations.list', {}); | ||
// $ExpectType __DangerouslyOutmodedAsyncIteratorSignatureWrapper<WebAPICallResult> | ||
web.paginate('conversations.list') as __DangerouslyOutmodedAsyncIteratorSignatureWrapper<WebAPICallResult>; | ||
|
||
// $ExpectType __DangerouslyOutmodedAsyncIteratorSignatureWrapper<WebAPICallResult> | ||
web.paginate('conversations.list', {}) as __DangerouslyOutmodedAsyncIteratorSignatureWrapper<WebAPICallResult>; | ||
|
||
// $ExpectType Promise<void> | ||
web.paginate('conversations.list', {}, () => false); | ||
|