Skip to content

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

Merged
developit merged 4 commits into
developit: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 into
developit:masterfrom
Hotell:add-ts-generation

Conversation

@Hotell

@Hotell Hotell commented May 25, 2020

Copy link
Copy Markdown
Contributor

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:

Comment thread src/index.js
* @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)

Comment thread src/index.js
* @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

Comment thread tsconfig.json

/* 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

Comment thread tsconfig.json
// "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

Comment thread tsconfig.json
"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)

Comment thread package.json
"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

@marvinhagemeister marvinhagemeister left a comment

Copy link
Copy Markdown

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 🙌

Comment thread src/index.js Outdated
Comment thread src/index.js

/** */
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

Shuunen commented Jun 17, 2020

Copy link
Copy Markdown

"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