I made the show on the topic: gr2m/helpdesk#29
An approach that eventually worked: TypeScript playground
The goal here is
-
If authStrategy is not set, require auth to be set to a string (token)
-
If authStrategy is set, make sure it adheres to a common interface:
- a synchronous "strategy" function, which returns an asynchrnous "auth" function
- the returned "auth" function has a
.hook property that can be used to hook into the request lifecycle
- How authentication strategies work
and derive the types for auth from the strategy function options
-
Make it work for custom classes created with .withDefaults(), e.g.
const AppOctokit = Octokit.defaults({ authStrategy: createAppAuth })
const appOctokit = new AppOctokit()
// ^ complains that `auth` must be set to `{ appId: string, privateKey: string, ... etc }`