Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial Typescript support #102

Merged
merged 9 commits into from
Apr 5, 2022
Merged

Add initial Typescript support #102

merged 9 commits into from
Apr 5, 2022

Conversation

aalmazan
Copy link
Contributor

@aalmazan aalmazan commented Apr 1, 2022

Description of the change

Adds tsconfig.json and typescript along with some updates due to tsc compiler errors.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Related issues

Fixes

Checklists

Development

  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development
  • No previous tests unrelated to the changed code fail in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached.
  • At least one reviewer has been requested
  • Changes have been reviewed by at least one other engineer
  • The relevant project board has been selected in Projects to auto-link to this pull request

@aalmazan aalmazan requested review from benogle and newhouse April 1, 2022 00:30
Comment on lines -527 to -547

static _prepareGraphQLBase64 (data, options = {}) {
const { filename, mimetype } = options
if (!filename) {
throw new Error('options.filename must be provided for Base64 upload')
}
if (!mimetype) {
throw new Error('options.mimetype must be provided for Base64 upload')
}

if (options.bufferize) {
const buffer = Buffer.from(data, 'base64')
return this._prepareGraphQLBuffer(buffer, options)
}

return {
data,
filename,
mimetype,
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got an error inside this method but it seems like we don't use it anymore?

@newhouse
Copy link
Contributor

newhouse commented Apr 1, 2022

I'm not 100% following what the goal is here?

Is it to write the source code in Typescript and then boil it down to JS? That's what I would think the goal is, right? If that's the case, then there are a few things to fix here:

  • The tsconfig should not have emitDeclarationOnly: true...we want the compiler to output JS files from the TS source files.
  • The tsconfig should carefully choose the target and lib values to match with the version of Node that we want the package to support. It's basically like telling it how to babelize things.
  • The /dist folder should not be checked into github, and should be .gitignore'd. The output data should be an artifact of the TS compiling command. However, the /dist folder will be included in NPM publish, and will end up on Users' machines when they install this package.
  • The source files should probably be renamed to *.ts.

I can walk you through all this and whatever else I know about Typescript and Node / NPM packages...ping me!

@aalmazan
Copy link
Contributor Author

aalmazan commented Apr 4, 2022

I'm not 100% following what the goal is here?

This PR isn't for converting the code base to have typescript support, but to have initial typescript *.d.ts files (issue linked above your comment).

The tsconfig should carefully choose the target and lib values to match with the version of Node that we want the package to support. It's basically like telling it how to babelize things.

Yeah probably needed to pay attention to that part of the config. Switching to:

    "target": "es2021",
    "module": "commonjs",

The /dist folder should not be checked into github, and should be .gitignore'd. The output data should be an artifact of the TS compiling command. However, the /dist folder will be included in NPM publish, and will end up on Users' machines when they install this package.

Yes this is on purpose. From the typescript docs, the generated .d.ts file path resolution defaults will eventually check dist/. IMO I'd prefer that over having *.d.ts files beside every .ts|js file.

EDIT: Changed it to a more obvious types/ dir since I glossed over the part about defining it in package.json. Updated.

Copy link
Contributor

@benogle benogle left a comment

Choose a reason for hiding this comment

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

Looks good to me! The last thing would be to make sure it can be consumed by a toy typescript project

src/index.js Outdated
@@ -1,5 +1,6 @@
const fs = require('fs')

const { ReadStream } = require('fs')
Copy link
Contributor

Choose a reason for hiding this comment

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

was this being used before without import?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. That snuck in while I was updating something. Removing.

rateLimiterPromiseResolver: (value: any) => void;
_setRateLimiter({ tokens, intervalMs }: {
tokens: any;
intervalMs: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

Any easy way to inject types for simple things like this? i.e. this should be an int

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah looks like it should generate properly with JSDoc comments. Will add that.

Comment on lines 33 to 34
responseQuery: any;
mutation: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

strings here

@@ -3,6 +3,7 @@
"version": "2.9.4",
"description": "Anvil API Client",
"main": "src/index.js",
"types": "./types/index.d.ts",
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@newhouse
Copy link
Contributor

newhouse commented Apr 4, 2022

seems like a fair amount of JSDoc'ing could be added to make this really worth it?

@aalmazan aalmazan merged commit 1c4d07d into master Apr 5, 2022
@aalmazan aalmazan deleted the aa/initial-ts-support branch April 5, 2022 00:14
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.

3 participants