Skip to content

@type on http(s) import #46936

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

Closed
5 tasks done
loynoir opened this issue Nov 28, 2021 · 2 comments
Closed
5 tasks done

@type on http(s) import #46936

loynoir opened this issue Nov 28, 2021 · 2 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@loynoir
Copy link

loynoir commented Nov 28, 2021

Suggestion

/**
 * @type {import('chai')}
 */
import { expect } from 'https://cdn.skypack.dev/chai'

Sugar for

// @ts-ignore
import { expect as _expect } from 'https://cdn.skypack.dev/chai'
/**
 * @type {import('chai')['expect']}
 */
const expect = _expect

🔍 Search Terms

jsdoc @type http loader ESM skypack .d.ts

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Alternatively, maybe let tsconfig.compilerOptions.paths accept RegExp

📃 Motivating Example

💻 Use Cases

@ncpa0cpl
Copy link

You can add typing to a module via declare module. Create .d.ts file with this:

declare module "https://cdn.skypack.dev/chai" {
  import chai from "chai";
  export = chai;
}

and you will get the same result you want

@RyanCavanaugh RyanCavanaugh added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Nov 29, 2021
@loynoir
Copy link
Author

loynoir commented Nov 30, 2021

Yeah, working. 😄
Not very graceful, but I'm ok to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants