Skip to content

feat: add proper JSDoc annotations to all public api and generate TS …#33

Merged
developit merged 4 commits intodevelopit:masterfrom
Hotell:add-ts-generation
Jul 15, 2020
Merged

feat: add proper JSDoc annotations to all public api and generate TS …#33
developit merged 4 commits intodevelopit:masterfrom
Hotell:add-ts-generation

Conversation

@Hotell
Copy link
Copy Markdown
Contributor

@Hotell Hotell commented May 25, 2020

Closes #22

  • adds TS type generation on build which produces high quality types ( like axios )
  • all public API's are properly typed and use generics
  • adds strict type checking for implementation (with lowering the strictness level - as it's not that straightforward in vanilla codebase)

image

NOTES:

* @property {Options} config the request configuration
* @property {any} data the decoded response body
* @property {T} data the decoded response body
* @property {Headers} headers
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added all fields that are assigned to the response to properly match implementation (dunno if it's on purpose, or we wanna strictly "match" axios response - in that case those need to be removed + omit those within implementation)

* @public
* @type {AbortController}
*/
redaxios.CancelToken = /** @type {any} */ (self).AbortController || Object;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is TypeScript dom types issue as AbortController is not defined on Window interface


/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"suppressImplicitAnyIndexErrors": true,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

easy up strict checks

// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
"noImplicitThis": false, /* Raise error on 'this' expressions with an implied 'any' type. */
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

easy up strict checks

"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
},
"include": [
"src"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enable on src/ only (excluding tests)

"karmatic": "^1.4.0",
"microbundle": "^0.11.0",
"sinon": "^8.0.4",
"typescript": "3.9.3",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't have to be as direct dep, microbundle will handle that in future

Copy link
Copy Markdown

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic! Love it 🙌


/** */
export default (function create(defaults) {
export default (function create(/** @type {Options} */ defaults) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's easier to break the export and declaration out, I think microbundle+terser will collapse them all the same:

/** @param {Options} defaults */
function create() {
  // ...
}
export default create();

@Shuunen
Copy link
Copy Markdown

Shuunen commented Jun 17, 2020

"Compressed Size / build (pull_request)" fails, why ? Looking at "details" didn't helped me understand the issue here, this MR increased the pkg size too much ?

@marvinhagemeister
Copy link
Copy Markdown

The relevant error message is:

 src/index.js(210,25): error TS2339: Property 'withCredentials' does not exist on type 'Options'.

Looks like there is a type error in the changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add typescript types

4 participants