-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Adds existing npm lib multicodec + tests #41404
Conversation
Signed-off-by: Carson Farmer <carson.farmer@gmail.com>
@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'; |
There was a problem hiding this comment.
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?
👋 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 📊
|
There was a problem hiding this 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.
@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>
Typo fixed, good catch!
Maybe I'm missing something, but I don't see any evidence of this? The |
🔔 @armanio123 - Thanks for your review of this PR! Can you please look at the new code and update your review status if appropriate? |
Here's documentation of If you check file https://unpkg.com/multicodec@1.0.0/dist/index.js, line 9:
That's where the global variable is being assigned. |
Signed-off-by: Carson Farmer <carson.farmer@gmail.com>
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 |
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 |
Cool, so that's great. But is it only available globally in a browser context? If I look at the 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>
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 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. |
I just published |
Thanks so much for a) explaining this, super helpful, and b) approving and merging! Cheers @armanio123! |
Signed-off-by: Carson Farmer carson.farmer@gmail.com
Please fill in this template.
npm test
.)npm run lint package-name
(ortsc
if notslint.json
is present).Select one of these and delete the others:
If adding a new definition:
.d.ts
files generated via--declaration
dts-gen --dt
, not by basing it on an existing project.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 havenoImplicitAny
,noImplicitThis
,strictNullChecks
, andstrictFunctionTypes
set totrue
.