RapiDoc icon indicating copy to clipboard operation
RapiDoc copied to clipboard

Feat/typescript migration

Open sroucheray opened this issue 2 years ago • 4 comments

Hi @mrin9,

So here is the branch where I migrated the project to Typescript.

  • [X] Migrate all files from JS to TS
    • [X] Use openapi-types lib wherever possible
    • [X] Add extra typings where it was feasible
    • [X] Cast to typing where some type incompatibility may arise
    • [X] When I had not other way I added some anys where typing were difficult to understand
    • [X] Try NOT to fix code yet, unless typings made it impossible to compile
    • [ ] Migrate rapidoc-mini.js (commented out for now to avoid extra work)
  • [X] Update tsconfig and webpack to adapt the build pipeline (commands did not change)
    • [X] build passes and produces artefacts (js and typing files)

The remaining tasks I see

  • [ ] Improve / Cleanup custom typings by someone who has more knowledge about the shape of object
    • [ ] Cleanup code wherever typings alert
    • [ ] Replace remaining any references in the code by proper types
    • [ ] Replace remaining 'as ...' type casting added in the code because of lack of knowledge about objects shapes or union types were not properly discriminated in the original code.
    • [ ] Check // TODO: Typescript migration... in the code to find mistake in original code now catched by the Typescript compiler (usually it needs refactor or removal)
  • [ ] Testing
  • [x] Rebase on master and integrate last modification
  • [ ] Simplify and make some portions of code more robust which should be much easier with the help of typings
  • [ ] Add unit tests

One note about functions. You'll see that many functions have a first parameter named this, it's not a real parameter but the way typescript make it clear on which type of object the function is called (as many utility functions are called with call). https://www.typescriptlang.org/docs/handbook/2/functions.html#declaring-this-in-a-function

Example

...
export default function jsonSchemaViewerTemplate(this: RapiDocJSONSchemaViewerElement, isMini = false) {
...

sroucheray avatar Dec 13 '22 15:12 sroucheray

Side note: my last commit is a fix for the response status not properly set when an error occurred. I encountered this error while working on a specific API. I took the opportunity to narrow down the type of the responseStatus to success | error instead of a string. Typescript makes it clear what this property can hold as a value now !

sroucheray avatar Dec 29 '22 16:12 sroucheray

I merged master in my branch to keep up to date with latest commits

sroucheray avatar Aug 25 '23 12:08 sroucheray

Waiting for release.

ricodealma avatar Jul 09 '24 11:07 ricodealma

Waiting for release.

Unfortunately, the main author did not give much interest in this branch since the MR. I tried to maintain it in phase with master as much as I can, though.

sroucheray avatar Jul 09 '24 12:07 sroucheray