Kotlin / dukat

Converter of <any kind of declarations> to Kotlin external declarations
552 stars 42 forks source link

Infer T$NNN interface names from a use site #364

Open vlsi opened 4 years ago

vlsi commented 4 years ago

https://www.npmjs.com/package/@octokit/types

Sample usage:

import { Endpoints } from "@octokit/types";

type listUserReposParameters = Endpoints["GET /repos/:owner/:repo"]["parameters"];
type listUserReposResponse = Endpoints["GET /repos/:owner/:repo"]["response"];

async function listRepos(
  options: listUserReposParameters
): listUserReposResponse["data"] {
  // ...
}

Types:

export interface Endpoints {
    /**
     * @see https://developer.github.com/v3/apps/#delete-an-installation-for-the-authenticated-app
     */
    "DELETE /app/installations/:installation_id": {
        parameters: AppsDeleteInstallationEndpoint;
        request: AppsDeleteInstallationRequestOptions;
        response: OctokitResponse<any>;
    };
    /**
     * @see https://developer.github.com/v3/apps/#unsuspend-an-app-installation
     */
    "DELETE /app/installations/:installation_id/suspended": {
        parameters: AppsUnsuspendInstallationEndpoint;
        request: AppsUnsuspendInstallationRequestOptions;
        response: OctokitResponse<any>;
    };

Generated Kotlin:

external interface Endpoints {
    operator fun get(key: String): Any?
    operator fun set(key: String, value: `T$18`)
    operator fun set(key: String, value: `T$19`)
    operator fun set(key: String, value: `T$20`)
    operator fun set(key: String, value: `T$27`)
...
    var DELETE /app/installations/:installation_id: `T$10`
    var DELETE /app/installations/:installation_id/suspended: `T$11`
    var DELETE /applications/:client_id/grant: `T$12`
    var DELETE /applications/:client_id/grants/:access_token: `T$13`
    var DELETE /applications/:client_id/token: `T$14`
    var DELETE /applications/:client_id/tokens/:access_token: `T$15`
}

external interface `T$10` {
    var parameters: `T$831` /* `T$831` & RequiredPreview<String /* "machine-man" */> */
    var request: AppsDeleteInstallationRequestOptions
    var response: OctokitResponse<Any>
}

external interface `T$11` {
    var parameters: AppsUnsuspendInstallationEndpoint
    var request: AppsUnsuspendInstallationRequestOptions
    var response: OctokitResponse<Any>
}

What if T$10 was Endpoints_DELETE_app_installations_installation_id ("enclosing" interface name + "property" name)?