-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
ScriptKind.Deferred treated as LanguageVariant.Standard #60125
Comments
This would just change how the problem could happen. In a non-JSX file you might need have a I don't know why typescript-eslint is using |
This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
@RyanCavanaugh sorry for the delay; was looking more into the source of From what I understand Marking the file as
This is due to the project service being unable to resolve the file as part of a project because it's not a known extension and thus means ts doesn't respect it as part of the program root files. The reason the extra file is not part of the root files when marking as https://github.com/microsoft/TypeScript/blob/main/src/compiler/utilities.ts#L9867 ...mapDefined(extraFileExtensions, x => !flatBuiltins.includes(x.extension as Extension) ? [x.extension] : undefined) Resolves the issues downstream when setting the extra file extensions. I can't see from usages why we would need to exclude any extra extensions that are not There is also a lot of jiggery pokery in other tools such as ( |
We could try a PR for this. |
There is host configuration command on tsserver that lets you set script kind for file extensions .. using deferred is just default and let plugins handle through wrapping getScriptKind kind of facility so I don’t think the change you are suggesting is the one you need |
Also from plugin perspective they are part of root projects and they are provided through |
service.setHostConfiguration({
extraFileExtensions: extraFileExtensions.map(extension => ({
extension,
isMixedContent: false,
scriptKind: ts.ScriptKind.Deferred,
})),
}); Typescript eslint does what you are describing i believe. However if you say set set That method is then used in many places (when building up the project state). Which then means the extra file is not added to the Is there an alternative host configuration that should be set? |
When configuring the language service host with extra file extensions, the file extension is only regarded as supported if its `Deferred` or like JS. If the host can delare a specific ScriptKind such as `TSX` for a file then it will be stripped out with getSupportedExtensions. This then later causes the programs rootFiles to not include the extra file extension, and thus be excluded from the program. If using `Deferred` then the file when parsed will be treated as TS and fail to compile when using (J)TSX syntax. In majority of cases the script kind will be known by the consumer and they can set the explicit script kind for the extra file extension. Adjust the logic for `getSupportedExtensions` to include any extra file extension that are not built in. This way all explicit extra file extensions added will be included in the project/programs root files and an explicit `scriptKind` can be set. resolves: microsoft#60125
When configuring the language service host with extra file extensions, the file extension is only regarded as supported if its `Deferred` or like JS. If the host can delare a specific ScriptKind such as `TSX` for a file then it will be stripped out with getSupportedExtensions. This then later causes the programs rootFiles to not include the extra file extension, and thus be excluded from the program. If using `Deferred` then the file when parsed will be treated as TS and fail to compile when using (J)TSX syntax. In majority of cases the script kind will be known by the consumer and they can set the explicit script kind for the extra file extension. Adjust the logic for `getSupportedExtensions` to include any extra file extension that are not built in. This way all explicit extra file extensions added will be included in the project/programs root files and an explicit `scriptKind` can be set. resolves: microsoft#60125
🔎 Search Terms
Deferred ScriptKind TSX
Deferred ScriptKind Standard
Vue, eslint, tsx parser error
🕗 Version & Regression Information
Currently looking at TypeScript 5.5+ likely affects most versions of typescript.
⏯ Playground Link
No response
💻 Code
Not specific to TS code but compiler and parsing.
🙁 Actual behavior
When using typescript-eslint with there new projectSettings option, along side vue with tsx. The file fails to parse
Deferred ScriptKinds are treated as
LanguageVariant.Standard
rather thanLanguageVariant.JSX
https://github.com/microsoft/TypeScript/blob/main/src/compiler/parser.ts#L1746
https://github.com/microsoft/TypeScript/blob/main/src/compiler/utilities.ts#L8832
🙂 Expected behavior
Under the assumption that ScriptKind.Deferred could be treated as
LanguageVariant.JSX
then this resolvestypescript-eslints
issue with parsing extraFileExtensions such asvue
files.I'm unsure what the consequences and other use cases of
ScriptKind.Deferred
are so it could be as simple as adjustinggetLanguageVariant
.Additional information about the issue
typescript-eslint/typescript-eslint#9934
The text was updated successfully, but these errors were encountered: