JS/TS type information for modules hosted on a web url?

49 views Asked by At

Say I host a client script on a domain along with it's associated type declaration file.

https://example.com/foo.js
https://example.com/foo.d.ts
// foo.js
export const foo = "Hello World"
// foo.d.ts
export declare const foo: string

My expectation is that I will use this directly in the browser console as a client script to enhance/augment an existing web experience (either using something like TamperMonkey/a custom Chrome extension, or by pasting a script in the debug console/javascript bookmark)

I have a library of utilities that I use to compose larger scripts from and would like to host in the same way I do the foo.js example above.

When writing a large script that composes this remotely stored scripts, I don't have any support from the IDE as it does not resolve the URL or search for type information remotely.

import { foo } from 'https://example.com/foo.js' // No type information

It doesn't populate types even if I write my file using JSDoc rather than TypeScript type declarations indicating that it simply doesn't resolve remote files

// https://example.com/bar.js

/** @type {string} */
export const bar = 'something'
import { foo } from 'https://example.com/bar.js' // Still no type information

Is there a way to get the TypeScript language server to resolve files hosted remotely and populate type information?

0

There are 0 answers