-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Proposal: guidance on modules/globals #6125
Comments
Relevant discussion here too |
Related: microsoft/TypeScript#4337 |
Yea I'm not sure how to fix this, but I agree it's crappy. Seems like the best solution would be to have support in the test runner to dynamically switch out what gets imported (some kind of preprocessor directive, maybe?). Alternatively we could only test the module version or the namespace version but not both. That's how React was for a long time, I added the namespace tests just recently for consistency but definitely not happy about duplication. |
Agreed.
Not sure we need something as heavyweight as support in the language... We could do this via some sort of special comment scheme. There's already good support for this. e.g. the following is /* switch-zone-start */
/// <reference path="node-uuid.d.ts" />
import * as uuid from "node-uuid";
/* switch-zone-end */
// tests follow per https://github.com/myitcv/DefinitelyTyped/blob/node_uuid_es6_module/node-uuid/node-uuid-tests.ts Then for every other file
Then tests run. Thoughts? |
No, but it's related. We could potentially take cues from that in case language support was coming. I mean what you suggested with comments are essentially preprocessor directives. In any case, I think we're on the same page minus implementation specifics. The basic idea being that the test runner would need to do something special involving scanning and manipulating the test files. I would suggest maybe even a simpler scheme not involving /* test: global */
/// <reference path="node-uuid-global.d.ts" />
/* test-end */
/* test: module */
/// <reference path="node-uuid.d.ts" />
import * as uuid from "node-uuid";
/* test-end */
/// ... tests .... Where each test file is simply run multiple times for each occurrence of |
Hi thread, we're moving DefinitelyTyped to use GitHub Discussions for conversations the To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the TypeScript Community Discord and mention the issue in the |
I would like to suggest an update to the best practices document, namely that we establish and document some sort of pattern, similar to React, for modules vs. global ambient declarations. The gist is very similar to my comments in #6112.
Idea being that hopefully:
I've cited the React pattern in #6112 on the basis it seems like the right approach to follow.
lodash
I believe requires a slightly different pattern because we are effectively exporting a variable and a namespace (hence can't useexport =
).The one question I would add is whether we can improve the test file situation with this pattern: in the React package, the only difference between
react-tests.ts
andreact-global-tests.ts
is as follows:It seems a burden to have to maintain both, with the difference being a single reference and a single import.
Would welcome your thoughts @borisyankov @vvakame @johnnyreilly @basarat
The text was updated successfully, but these errors were encountered: