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

[v2] type checking and intellisense support #3702

Open
trusktr opened this issue Jul 5, 2023 · 2 comments
Open

[v2] type checking and intellisense support #3702

trusktr opened this issue Jul 5, 2023 · 2 comments

Comments

@trusktr
Copy link

trusktr commented Jul 5, 2023

(not for code in Prism inside a web app, but for people consuming the Prism library, in their IDE)

Currently the v2 build provides no types for consumers. We should output declaration files that work well with vanilla ES Module usage (ensuring it works with vanilla ES Modules ensures the most compatibility: if it works with vanilla, it will work with everything else because it will be in the most standard way that tools are aligning with).

@trusktr
Copy link
Author

trusktr commented Jul 5, 2023

To make this have a high chance of working well in a way that is easy to understand, I recommend we change from the current chunked output, and simply output vanilla ES Modules that match the exact same structure as our source code.

Essentially, the dist/ folder should simply be a mirror of our src/ folder: a one-to-one mapping with merely types stripped, filenames converted from .ts to .js, plus type declaration files emitted for type checking and intellisense on the consumer end.

Anything else will be more complicated: more to understand and think about, more likely someone looking at source gets confused when looking at dist/ output, type declaration output will be more difficult to create because TypeScript will not know how to match Rollup's format, and if we then introduce a Rollup type declaration bundler this will not result in types being visible for vanilla ES module imports of any file but only for the index files.

Simplifying the outputs will help everyone's mental model on both sides (prism authors + consumers).

@trusktr trusktr mentioned this issue Jul 5, 2023
2 tasks
@trusktr
Copy link
Author

trusktr commented Jul 6, 2023

Alright, here's my initial vision for this simplification, including example app and Node ESM import test in the sample app:

Note that with this setup, we get full intellisense and type checking.

intellisense

.

If we Go-To-Definition, we are taken to the TypeScript source (not just the declaration file):

go-to-def.mov

.

Lastly, this exposes one problem with the current type definitions of languages. The type definitions for the language objects are not visible to VS Code for some reason, and we get no intellisense and .grammar methods are type any:

language-types-issue.mov

I'm guessing this may have to do with the type casts (?), f.e. as LanguageProto<"typescript">.

Now that we have types flowing into consumer code in the simplest-possible ESM setup, we can start to work on the last things such as these missing types for end user code.

That's all I have time for today. I would love if you can take this for a spin and give some thoughts on it.

Last things needed on the PR's current path:

  • ensure the components.json build is handled if needed
  • fix last type definition issues

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

No branches or pull requests

1 participant