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

Adds existing npm lib multicodec + tests #41404

Merged
merged 4 commits into from
Jan 14, 2020

Conversation

carsonfarmer
Copy link
Contributor

Signed-off-by: Carson Farmer carson.farmer@gmail.com

Please fill in this template.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Add or edit tests to reflect the change. (Run with npm test.)
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run npm run lint package-name (or tsc if no tslint.json is present).

Select one of these and delete the others:

If adding a new definition:

  • The package does not already provide its own types, or cannot have its .d.ts files generated via --declaration
  • If this is for an NPM package, match the name. If not, do not conflict with the name of an NPM package.
  • Create it with dts-gen --dt, not by basing it on an existing project.
  • Represents shape of module/library correctly
  • tslint.json should be present and it shouldn't have any additional or disabling of rules. Just content as { "extends": "dtslint/dt.json" }. If for reason the some rule need to be disabled, disable it for that line using // tslint:disable-next-line [ruleName] and not for whole package so that the need for disabling can be reviewed.
  • tsconfig.json should have noImplicitAny, noImplicitThis, strictNullChecks, and strictFunctionTypes set to true.

Signed-off-by: Carson Farmer <carson.farmer@gmail.com>
@typescript-bot typescript-bot added New Definition This PR creates a new definition package. Awaiting reviewer feedback labels Jan 5, 2020
@typescript-bot
Copy link
Contributor

typescript-bot commented Jan 5, 2020

@carsonfarmer Thank you for submitting this PR!

Because this is a new definition, a DefinitelyTyped maintainer will be reviewing this PR in the next few days once the Travis CI build passes.

In the meantime, if the build fails or a merge conflict occurs, I'll let you know. Have a nice day!

/**
* Map of codecConstant to code
*/
export * from './constants';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could this 'feature' be better represented using a namespace?

@typescript-bot
Copy link
Contributor

👋 Hi there! I’ve run some quick measurements against master and your PR. These metrics should help the humans reviewing this PR gauge whether it might negatively affect compile times or editor responsiveness for users who install these typings.

Let’s review the numbers, shall we?

These typings are for a package that doesn’t yet exist on master, so I don’t have anything to compare against yet! In the future, I’ll be able to compare PRs to multicodec with its source on master.

Comparison details 📊
Batch compilation
Type count 10170
Assignability cache size 3022
Language service measurements
Samples taken 120
Identifiers in tests 120
getCompletionsAtPosition
    Mean duration (ms) 369.3
    Mean CV 11.9%
    Worst duration (ms) 483.1
    Worst identifier print
getQuickInfoAtPosition
    Mean duration (ms) 362.1
    Mean CV 11.4%
    Worst duration (ms) 444.5
    Worst identifier print
System information
Node version v12.13.1
CPU count 2
CPU speed 2.294 GHz
CPU model Intel(R) Xeon(R) CPU E5-2673 v4 @ 2.30GHz
CPU Architecture x64
Memory 6.8 GiB
Platform linux
Release 4.15.0-1064-azure

Copy link
Contributor

@armanio123 armanio123 left a comment

Choose a reason for hiding this comment

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

I think multicodec also provides a global value. See https://www.typescriptlang.org/docs/handbook/declaration-files/library-structures.html#global-libraries for details on how to represent this.

types/multicodec/index.d.ts Outdated Show resolved Hide resolved
@typescript-bot typescript-bot moved this from Review to Needs Author Attention in Pull Request Status Board Jan 7, 2020
@typescript-bot typescript-bot added Revision needed This PR needs code changes before it can be merged. and removed Awaiting reviewer feedback labels Jan 7, 2020
@typescript-bot
Copy link
Contributor

@carsonfarmer One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits or comments. Thank you!

Signed-off-by: Carson Farmer <carson.farmer@gmail.com>
@carsonfarmer
Copy link
Contributor Author

Typo fixed, good catch!

I think multicodec also provides a global value. See https://www.typescriptlang.org/docs/handbook/declaration-files/library-structures.html#global-libraries for details on how to represent this.

Maybe I'm missing something, but I don't see any evidence of this? The aegir build script produces a webpack umd, but doesn't look like there are any globals available..? Could you point me to where I might find this?

@typescript-bot
Copy link
Contributor

🔔 @armanio123 - Thanks for your review of this PR! Can you please look at the new code and update your review status if appropriate?

@armanio123
Copy link
Contributor

armanio123 commented Jan 10, 2020

Maybe I'm missing something, but I don't see any evidence of this? The aegir build script produces a webpack umd, but doesn't look like there are any globals available..? Could you point me to where I might find this?

Here's documentation of multicodec used on the browser: https://multiformats.github.io/js-multicodec/

If you check file https://unpkg.com/multicodec@1.0.0/dist/index.js, line 9:

root["Multicodec"] = factory();

That's where the global variable is being assigned.

Signed-off-by: Carson Farmer <carson.farmer@gmail.com>
@carsonfarmer
Copy link
Contributor Author

Ah I see, thanks @armanio123, I didn't read that initial link you posted properly. My apologies, yes you are right, and I think the added export as namespace Multicodec should cover it. Though it wasn't clear to me how best to 'test' this?

@armanio123
Copy link
Contributor

armanio123 commented Jan 13, 2020

Though it wasn't clear to me how best to 'test' this?

Since you're declaring a global variable by exporting the namespace, you should be able to access it's properties en methods just by using Multicodec on the test file (no import required).

@carsonfarmer
Copy link
Contributor Author

Cool, so that's great. But is it only available globally in a browser context? If I look at the "main" entry in the package.json I see "src/index.js", which does not have anything exported globally. Is this still 'ok' from a ambient types perspective? Apologies for my ignorance here, this is apparently the first package that has a global export that I've written types for 😬.

So I guess my final question here is, is it misleading to have globally exported types in say a NodeJS context? I see that if I do include the import, this masks the global value, which makes sense. However, in NodeJS, if I don't import the package, I won't actually have it in my global namespace...

Signed-off-by: Carson Farmer <carson.farmer@gmail.com>
@armanio123
Copy link
Contributor

So I guess my final question here is, is it misleading to have globally exported types in say a NodeJS context? I see that if I do include the import, this masks the global value, which makes sense. However, in NodeJS, if I don't import the package, I won't actually have it in my global namespace...

I can see how this is confusing, but that's how umd modules work. It would be up to the developer to understand the library and decide the best implementation. As you correctly stated, in the case of a NodeJs environment, you require specify the import. For the case of the browser you must reference the global library by using a script block (I think the author documented this to be on the dist folder) and make the global variable available.

Btw for test purposes both scenarios should be ok. You can either decide to import or use the global scope. I'll approve and merge the PR.

@armanio123 armanio123 merged commit f4f29cb into DefinitelyTyped:master Jan 14, 2020
Pull Request Status Board automation moved this from Needs Author Attention to Done Jan 14, 2020
@typescript-bot
Copy link
Contributor

I just published @types/multicodec@1.0.0 to npm.

@carsonfarmer
Copy link
Contributor Author

Thanks so much for a) explaining this, super helpful, and b) approving and merging! Cheers @armanio123!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Definition This PR creates a new definition package. Revision needed This PR needs code changes before it can be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants