Skip to content

Commit 539a864

Browse files
committed
Test repository for microsoft/TypeScript#4913. Compiles and runs!
1 parent 6fb069e commit 539a864

25 files changed

+2370
-0
lines changed

poelstra4/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules/bluebird/

poelstra4/README.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
This tree shows an example of having two 'native' Typescript packages (`mylib` and `myotherlib`),
2+
that both use a different version of the same non-TS package (`myutils`).
3+
4+
It is meant as a test for https://github.com/Microsoft/TypeScript/pull/4913
5+
6+
To make the example even more interesting, both ambient typings (`declare module "..." { }`) and 'proper external' typings are used.
7+
In `myotherlib`, `myutils` is proper external, but Bluebird and node were added as ambient typings (directly taken from DefinitelyTyped).
8+
9+
To test this yourself:
10+
```sh
11+
# Build the compiler with scoped-packages support (#4913)
12+
git clone [email protected]:weswigham/TypeScript.git
13+
cd TypeScript
14+
git checkout package-scopes
15+
jake local
16+
17+
# Build and run this project using the new compiler
18+
cd ..
19+
git clone https://github.com/basarat/typescript-node
20+
cd typescript-node/poelstra4
21+
node ../TypeScript/built/local/tsc.js
22+
npm install bluebird
23+
node myprogram.js
24+
```
25+
26+
Interesting things to note:
27+
* It compiles and runs! :)
28+
* Both versions of `myutils` can co-exist, i.e. the results from the function calls in `myprogram.ts` can be resolved,
29+
and the type of the `.foo` property is correct
30+
* The `Promise` type and e.g. `Buffer` are not available in `myprogram.ts` (this is indeed the intended behaviour!)
31+
* Typings for `myutils` need to be stored in `node_modules` to be found as external modules. They are typically
32+
provided by the 'parent' package (such as `mylib` and `myotherlib`), but the `node_modules` directory is not
33+
typically part of a repository/package. So either tooling should handle this, or a configurable search path
34+
(similar to, but different from `typings`) needs to be defined.
35+
* `myotherlib` contains a bluebird typing straight from DT, but also needs a 'wrapper' in
36+
`myotherlib/node_modules/bluebird.d.ts` to make `myotherlib/index.d.ts` work when included from `myprogram`.
37+
Same remark on having to provide the file in `node_modules`.

poelstra4/myprogram.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var mylib = require("mylib");
2+
var myotherlib = require("myotherlib");
3+
function assert(cond) {
4+
if (!cond) {
5+
throw new Error("assertion failed");
6+
}
7+
}
8+
var a = mylib.myfunc();
9+
var b = myotherlib.myotherfunc();
10+
var str = a.foo;
11+
var num = b.foo;
12+
assert(typeof a.foo === "string");
13+
assert(typeof b.foo === "number");
14+
myotherlib.myAsync().then(function (x) {
15+
console.log(x.foo); // 42
16+
});
17+
// These should give compile errors:
18+
// var p: Promise; // Promise is ambiently declared through `myotherlib`, but should not leak to here
19+
// var b: Buffer; // again ambiently declared through `myotherlib`

poelstra4/myprogram.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import mylib = require("mylib");
2+
import myotherlib = require("myotherlib");
3+
4+
function assert(cond: boolean): void {
5+
if (!cond) {
6+
throw new Error("assertion failed");
7+
}
8+
}
9+
10+
var a = mylib.myfunc();
11+
var b = myotherlib.myotherfunc();
12+
13+
var str: string = a.foo;
14+
var num: number = b.foo;
15+
16+
assert(typeof a.foo === "string");
17+
assert(typeof b.foo === "number");
18+
19+
myotherlib.myAsync().then((x) => {
20+
console.log(x.foo); // 42
21+
});
22+
23+
// These should give compile errors:
24+
// var p: Promise; // Promise is ambiently declared through `myotherlib`, but should not leak to here
25+
// var b: Buffer; // again ambiently declared through `myotherlib`

poelstra4/node_modules/mylib/index.d.ts

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poelstra4/node_modules/mylib/index.js

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poelstra4/node_modules/mylib/index.ts

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poelstra4/node_modules/mylib/node_modules/myutils.d.ts

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poelstra4/node_modules/mylib/node_modules/myutils/index.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poelstra4/node_modules/mylib/node_modules/myutils/package.json

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poelstra4/node_modules/mylib/package.json

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poelstra4/node_modules/mylib/tsconfig.json

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poelstra4/node_modules/myotherlib/index.d.ts

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poelstra4/node_modules/myotherlib/index.js

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poelstra4/node_modules/myotherlib/index.ts

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poelstra4/node_modules/myotherlib/node_modules/bluebird.d.ts

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poelstra4/node_modules/myotherlib/node_modules/myutils.d.ts

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poelstra4/node_modules/myotherlib/node_modules/myutils/index.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poelstra4/node_modules/myotherlib/node_modules/myutils/package.json

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poelstra4/node_modules/myotherlib/package.json

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poelstra4/node_modules/myotherlib/tsconfig.json

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)