Skip to content

feat: RestApiClient example #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 5, 2021
Merged

feat: RestApiClient example #68

merged 3 commits into from
Aug 5, 2021

Conversation

gr2m
Copy link
Owner

@gr2m gr2m commented Jul 20, 2021

This pull request currently fails because I don't know how to export a RestApiClient class type that is extending Base and has both the plugins and defaults implemented.

The JS code is simple enough

import { Base } from "../../index.js";

import { requestPlugin } from "./request-plugin.js";

export const RestApiClient = Base
  .withPlugins([requestPlugin])
  .withDefaults({ userAgent: "rest-api-client/1.0.0" });

But I'm not clear how to define the type declarations so that an import of RestApiClient would set the .request() instance method as well as RestApiClient.defaults

I think ideally I'd like to do something like this?

import { Base } from "javascript-plugin-architecture-with-typescript-definitions";
import { requestPlugin } from "./request-plugin.js"

type Defaults = {
  userAgent: string
}

export class RestApiClient extends Base<Defaults, [requestPlugin]> {}

But I'm not sure how that would work

import { Base } from "javascript-plugin-architecture-with-typescript-definitions";

export class RestApiClient extends Base.withDefaults({
  userAgent: "rest-api-client/1.0.0"
}) {}

RestApiClient.defaults.userAgent // string

When I try the TypeScript code above in this TypeScript playground then the resulting .D.TS code is quite complex.

So two things I want to figure out

  1. How to create a .d.ts file for a new class with custom defaults and plugins based on Base
  2. How to make step 1 as simple as possible

@JoshuaKGoldberg
Copy link
Collaborator

How to create a .d.ts file for a new class with custom defaults and plugins based on Base

Summarizing our 1:1 conversations here: until TypeScript supports a better syntax .d.ts for it, such as typeof class, I don't see a way to get something clean 😞

@gr2m gr2m merged commit d6b6a6a into main Aug 5, 2021
@gr2m gr2m deleted the rest-api-client-example branch August 5, 2021 20:11
@github-actions
Copy link

github-actions bot commented Aug 5, 2021

🎉 This PR is included in version 4.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants