Skip to content

Global library type declarations not recognized in inline <script> tags #250216

@Sight-wcg

Description

@Sight-wcg

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:

  1. 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
  }
}
  1. 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
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions