dnsimple / dnsimple-node

The DNSimple API client for Node.js.
https://developer.dnsimple.com/
MIT License
48 stars 19 forks source link

Extract TypeScript types to separate file and declare enum type values #175

Closed ghost closed 1 year ago

ghost commented 1 year ago

This moves common types (e.g. response data) to types.ts with names to allow them to be easily used and referenced from user code. Values of enums are also provided for stricter better type checking and autocomplete.

We export them directly at the package level instead of a submodule as it's not possible to import in a nested fashion in TS or JS. We do not have many exports at the package level anyway, so this is safe. We don't require directly importing from the file as we don't want to make the file path part of our public API. Therefore, types can be imported from user code as such:

import { Account, Certificate } from "dnsimple";
DXTimer commented 1 year ago

Looks like some more work needs to be done. Feel free to request a review again when PR is ready.

weppos commented 1 year ago

Out of curiosity, any chance we can generate these types from OpenAPI? In this way we both automate it, and validate the OpenAPI definition.

DXTimer commented 1 year ago

Out of curiosity, any chance we can generate these types from OpenAPI? In this way we both automate it, and validate the OpenAPI definition.

@weppos Yes, all the API methods and types are currently generated from the OpenAPI Spec definition. And it has surfaced some inconsistencies between the spec and the actual implementation, and all of those were fixed.

weppos commented 1 year ago

Yes, all the API methods and types are currently generated from the OpenAPI Spec definition. And it has surfaced some inconsistencies between the spec and the actual implementation, and all of those were fixed.

This is awesome! 👏