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

Importing types with checked JS #19411

Closed
azz opened this issue Oct 23, 2017 · 4 comments
Closed

Importing types with checked JS #19411

azz opened this issue Oct 23, 2017 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@azz
Copy link

azz commented Oct 23, 2017

TypeScript Version: 2.5.3

Code

In TypeScript, it is trivial to import a type from a package:

import { MyType } from "types-package";

function foo(bar: MyType) {}

However, with checked JS, as far as I can tell there's no way to achieve this. The following loosely demonstrates what I'm after.

/**
 * @typedef {import { MyType } from "types-package"} {MyType}
 * @param {MyType} bar
 */
function foo(bar) {}

Note that:

  1. types-package is a .d.ts only package, no runtime code.
  2. The specific use case I am working with is a module that implements an interface on the exported functions. Consider a VSCode extension, which exports an activate function, it is currently not possible to type the context parameter to that function if the extension is written in JS.
@azz
Copy link
Author

azz commented Oct 23, 2017

I've found a workaround. If your types package has an index.js with the contents:

module.exports = {};

Then you can import the types as usual and it works...

@mhegazy
Copy link
Contributor

mhegazy commented Oct 31, 2017

Duplicate of #14377

@mhegazy mhegazy marked this as a duplicate of #14377 Oct 31, 2017
@mhegazy mhegazy added the Duplicate An existing issue was already created label Oct 31, 2017
@azz
Copy link
Author

azz commented Nov 1, 2017

Ah, thanks. Happy to close as a duplicate.

@azz azz closed this as completed Nov 1, 2017
@azz
Copy link
Author

azz commented Nov 1, 2017

The solution mentioned here would be perfect: #14377 (comment)

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants