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

fix: handle typescript $$Generic special type #131

Merged
merged 2 commits into from
Sep 9, 2021

Conversation

SomaticIT
Copy link
Contributor

Fixes #127

This PR ignores the no-undef error when the referenced string is $$Generic.

It allows TypeScript developers to use generics in their components as specified in sveltejs/rfcs#38 and discussed in sveltejs/language-tools#442.

@Conduitry
Copy link
Member

Hm, this doesn't feel like the proper solution, but it might be all we have available to us at the moment. We currently have a way for the compiler to expose which global it's injected (like $$props and $-prefixed store autosubscriptions) but there's no way for preprocessors to expose this information. By leaving it up to the compiler to say which globals the linter shouldn't worry about, we don't need to worry about updating the linter every time we add a new magic global to the language.

@dummdidumm How worried are you about this introducing additional coupling between the linter and the current TS tooling? Does it make sense for the redesigned preprocessor API to provide for some way to handle this? I haven't thought any of this through.

@dummdidumm
Copy link
Member

This is a good point, if preprocessors could somehow append the globals that would solve this issue - partly. This isn't really a global at runtime, because it doesn't exist then, and therefore it's also not something that survives transpilation, the types are just gone. So is adding this to a list of globals - if that would be possible - really the semantically correct way?

In general I think some coupling between the linter and TS tooling is unavoidable as they operate on similar levels, which is another level than the Svelte compiler.

@SomaticIT
Copy link
Contributor Author

@Conduitry, indeed, the best way to handle this kind of "magic globals" would be to implement something at the compiler or the language tools level that could communicate to the linter a list of "exceptions" or "magics" of the language in a given context. This would help the maintenance of the linter.

However, this is something that should be studied and discussed heavily before it could be implemented correctly.

This PR tries to implement a quick way to allow typescript developers to use the new $$Generic magic type which enables a lot of new very powerful scenarios.

@Conduitry Conduitry merged commit e9f0250 into sveltejs:master Sep 9, 2021
@SomaticIT SomaticIT deleted the @fix/typescript-generics branch September 10, 2021 08:46
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

Successfully merging this pull request may close these issues.

Support new svelte $$Generic type
3 participants