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

Is it possible to get types for .coffee files without adding .d.ts files adjacent to them? #12

Closed
STRd6 opened this issue Apr 20, 2022 · 5 comments

Comments

@STRd6
Copy link

STRd6 commented Apr 20, 2022

First off, thank you for this extension! It is of great use to me overall.

In my simpler projects that have only one or two .coffee files I can easily access all the TypeScript types from imports and other shared locations. On my larger projects that have many .coffee files, some of which require others, they lose the types after the first layer.

Very basic example:

# src/jadelet.coffee
Jadelet = require "jadelet"

module.exports = Jadelet

This file works, all the types are available because the jadelet package exports the types.

Here is the problem...

# src/observable.coffee
{ Observable } = require "./jadelet"

module.exports = Observable

Cannot find module './jadelet' or its corresponding type declarations.CoffeeSense [TS](2307)

The module ./jadelet exists but TypeScript doesn't know about it. A work around is to create jadelet.d.ts files by manually compiling .coffee -> .js -> .d.ts but that seems excessive since all the data is "almost" there. Is it possible to tell TypeScript more directly that the types in these files exist?

With the JSDoc support .coffee files can pretty much export fully annotated types (especially after importing from ./typings/ etc.). Is there anything that can be done to let tsserver know that non-ts files could contain types?

@phil294
Copy link
Owner

phil294 commented Apr 20, 2022

I think all you need is to specify the file extension:

{ Observable } = require "./jadelet.coffee"

Autocompletion should even suggest this to you as it scans the available file paths.

Does this solve it for you?

Not sure if missing extensions can be achieved, I remotely remember that only jsx,tsx,js and ts can be implicitly imported and everything else needs explicit file extensions, maybe I am wrong though. CoffeeSense could probably also fix this

@phil294
Copy link
Owner

phil294 commented Apr 20, 2022

yeah custom file extensions are not allowed by typescript: microsoft/TypeScript#10939 but the extension should fix this imo. I'll fix it some other day so that your code also works nicely.

@STRd6
Copy link
Author

STRd6 commented Apr 20, 2022

Thanks for the fast response!

Adding the extension works though I would like the flexibility of not needing to specify it. That way I could have .ts or .coffee modules and not care about migrating from one to the other. It does seem that Node is general is moving towards explicit extensions but I prefer the 2014 aesthetics as I'm sure many other CoffeeScript hold outs do as well :)

@phil294
Copy link
Owner

phil294 commented Apr 21, 2022

This is now possible with version 1.9.0 (you need to check that VSCode updated the extension, it usually takes two reloads for that). Can you test this out and tell me if it now works as desired?

@STRd6
Copy link
Author

STRd6 commented Apr 21, 2022

@phil294 It works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants