-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Closed as not planned
Closed as not planned
Copy link
Description
Does this issue occur when all extensions are disabled?: Yes
- VS Code Version: 1.100.2
- OS Version: Windows_NT x64 10.0.19045
Description:
Type declarations for global libraries (.d.ts) are not respected when used within inline script tags, resulting in any typing and loss of auto-completion.
Potential Fix Reference:
This issue might be resolved by microsoft/vscode#171547 which improves type acquisition in HTML scripts.
Test File:
html-inline-script-tag-dts-test.zip
Reproduction Steps:
- Create global library with IIFE format attaching API to window:
Library Implementation
// myLib.js
window.myLib = {
name: "myLib",
version: '1.0',
sayHello: function() {
console.log("Hello!");
}
};Type Declaration (myLib.d.ts)
interface MyLib {
name: string;
version: string;
sayHello(): void;
}
declare const myLib: MyLib;
interface Window {
myLib: MyLib;
}Configuration (jsconfig.json)
{
"compilerOptions": {
"checkJs": true
}
}- Reference in HTML with inline script:
<!DOCTYPE html>
<html lang="en">
<body>
<script src="./myLib.js"></script>
<script src="./index.js"></script>
<script>
// ❌ Problem: Typed as `any` (no auto-completion)
window.myLib.sayHello();
// Comparison: jQuery types works correctly
// $.ajax();
</script>
</body>
</html>Expected Behavior
window.myLib should inherit MyLib type from declaration file in inline scripts
Actual Behavior
-
window.myLib resolves to any type
-
No auto-completion available
-
Type checking not performed
Additional Context
Works correctly in external JS files (e.g., index.js shown below):
// ✅ External JS file: Correctly typed as MyLib
window.myLib.version;Metadata
Metadata
Assignees
Labels
No labels