Type pollution with `global.d.ts` Y.js v14
Describe the bug
When using the @y/y package, there is a global.d.ts, which is meant to make it easy to not have to declare all of the TypeScript types throughout the project. The problem with this is two-fold:
- Currently,
@y/ydoes not actually emit the/// <reference types="../global.d.ts" />required to even have it work properly, within the built assets - This approach is flawed in that it will lead to global namespace pollution for any project which imports
@y/y
I tried to fix #1 and was successful with this patch (to insert the type reference which tsc annoyingly seems to strip out on build):
diff --git i/package.json w/package.json
index 1fea1e56..ad5390d4 100644
--- i/package.json
+++ w/package.json
@@ -12,7 +12,7 @@
"clean": "rm -rf dist",
"test": "NODE_ENV=development node ./tests/index.js --repetition-time 50",
"test-extensive": "node ./tests/index.js --production --repetition-time 10000",
- "dist": "npm run clean && PRODUCTION=1 tsc --skipLibCheck --noEmit false && test -e dist/src/index.d.ts",
+ "dist": "npm run clean && PRODUCTION=1 tsc --skipLibCheck --noEmit false && test -e dist/src/index.d.ts && { printf '/// <reference path=\"../../global.d.ts\" />\\n' && cat dist/src/index.d.ts; } > dist/src/index.d.ts.tmp && mv dist/src/index.d.ts.tmp dist/src/index.d.ts",
"lint": "markdownlint README.md && standard && tsc --skipLibCheck && npx dpdm --exit-code circular:1 --warning false --tree false src/index.js",
"debug": "npm run gentesthtml && 0serve -o test.html",
"debug:node": "node --inspect-brk tests/index.js",
But, then I realized that adding the global reference to a project means that all of these types declared in global.d.ts pollute the type namespace of any project using Y.js. So this solution is not sufficient.
To Reproduce N/A
Expected behavior I think the only way around this is to have JSDoc typedefs, or otherwise directly importing the types being referenced.
Screenshots N/A
Environment Information
@y/y
Additional context Add any other context about the problem here.
- I'm a sponsor
- This issue is a blocker for my project.
Source: yjs/yjs