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

fix #2388: allow consuming types without dom types #3679

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,14 @@ test-old-ts: platform-neutral | require/old-ts/node_modules
node-unref-tests: | scripts/node_modules
node scripts/node-unref-tests.js

lib-typecheck: lib-typecheck-node lib-typecheck-deno
lib-typecheck: lib-typecheck-node lib-typecheck-node-nolib lib-typecheck-deno

lib-typecheck-node: | lib/node_modules
cd lib && node_modules/.bin/tsc -noEmit -p tsconfig.json

lib-typecheck-node-nolib: | lib/node_modules
cd lib && node_modules/.bin/tsc -noEmit -p tsconfig-nolib.json

lib-typecheck-deno: lib/deno/lib.deno.d.ts | lib/node_modules
cd lib && node_modules/.bin/tsc -noEmit -p tsconfig-deno.json

Expand Down
22 changes: 22 additions & 0 deletions lib/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,3 +677,25 @@ export let version: string
// killing it before the test ends, so you have to call this function (and
// await the returned promise) in every Deno test that uses esbuild.
export declare function stop(): Promise<void>

// Note: These declarations exist to avoid type errors when you omit "dom" from
// "lib" in your "tsconfig.json" file. TypeScript confusingly declares the
// global "WebAssembly" type in "lib.dom.d.ts" even though it has nothing to do
// with the browser DOM and is present in many non-browser JavaScript runtimes
// (e.g. node and deno). Declaring it here allows esbuild's API to be used in
// these scenarios.
//
// There's an open issue about getting this problem corrected (although these
// declarations will need to remain even if this is fixed for backward
// compatibility with older TypeScript versions):
//
// https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/826
//
declare global {
namespace WebAssembly {
interface Module {
}
}
interface URL {
}
}
11 changes: 11 additions & 0 deletions lib/tsconfig-nolib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"module": "CommonJS", // Allow the "import assignment" syntax
"target": "es2017", // Allow calling APIs such as "Object.entries"
"strict": true,
"lib": [], // Omit "dom" to test what happens with the "WebAssembly" type, which is defined in "dom"
},
"include": [
"shared/types.ts",
],
}
6 changes: 1 addition & 5 deletions scripts/ts-type-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,7 @@ async function main() {
const tsc = path.join(__dirname, 'node_modules', 'typescript', 'lib', 'tsc.js')
const esbuild_d_ts = path.join(testDir, 'node_modules', 'esbuild', 'index.d.ts')
fs.mkdirSync(path.dirname(esbuild_d_ts), { recursive: true })
fs.writeFileSync(esbuild_d_ts, `
declare module 'esbuild' {
${types.replace(/export declare/g, 'export')}
}
`)
fs.writeFileSync(esbuild_d_ts, types)
let allTestsPassed = true

// Check tests without errors
Expand Down
Loading