Skip to content

Commit

Permalink
docs(README): remove obsolete "note on TypeScript"
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Nov 10, 2019
1 parent 1594e72 commit b6de2da
Showing 1 changed file with 0 additions and 52 deletions.
52 changes: 0 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
- [Hooks](#hooks)
- [Plugins](#plugins)
- [Build your own Octokit with Plugins and Defaults](#build-your-own-octokit-with-plugins-and-defaults)
- [⚠️ A note on TypeScript](#%E2%9A%A0%EF%B8%8F-a-note-on-typescript)
- [LICENSE](#license)

<!-- tocstop -->
Expand Down Expand Up @@ -376,57 +375,6 @@ const octokit = new MyActionOctokit();
const installations = await octokit.paginate("GET /app/installations");
```

<a name="a-note-on-typescript"></a>

### ⚠️ A note on TypeScript

When creating a new Octokit class using `.plugin()`, the TypeScript definitions `octokit` API extensions will get last when `.plugin()` or `.defaults()` is called on the new class again to derive yet another class. To workaround that, an intermediade class needs to be defined. For the example above, the code would look like this

```js
import { Octokit, OctokitOptions, OctokitPlugin, ReturnTypeOf, Constructor } from '@octokit/core'

const CoreWithPlugins = Octokit
.plugin([
paginate,
throttle,
retry
])

class CoreWithPluginsWorkaround extends CoreWithPlugins {
static plugin<T extends OctokitPlugin | OctokitPlugin[]>(pluginOrPlugins: T) {
const currentPlugins = this.plugins;
const newPlugins = Array.isArray(pluginOrPlugins)
? pluginOrPlugins
: [pluginOrPlugins];

const NewOctokit = class extends this {
static plugins = currentPlugins.concat(
newPlugins.filter(plugin => !currentPlugins.includes(plugin))
);
};

return NewOctokit as typeof NewOctokit & Constructor<ReturnTypeOf<T>>;
}

static defaults(defaults: OctokitOptions) {
return class OctokitWithDefaults extends this {
constructor(options: OctokitOptions = {}) {
super(Object.assign({}, defaults, options));
}
};
}
}

const MyActionOctokit = CoreWithPluginsWorkaround
.defaults({
authStrategy: require("@octokit/auth-action"),
userAgent: `my-octokit-action/v1.2.3`
});

const octokit = new MyActionOctokit();
const installations = await octokit.paginate("GET /app/installations");
```

## LICENSE

[MIT](LICENSE)

0 comments on commit b6de2da

Please sign in to comment.