API: Expose a way to figure out the `scriptKind`
See original GitHub issueSuggestion
🔍 Search Terms
api scriptkind
✅ Viability Checklist
My suggestion meets these guidelines:
- This wouldn’t be a breaking change in existing TypeScript/JavaScript code
- This wouldn’t change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript’s Design Goals.
⭐ Suggestion
It seems like at the moment the scriptKind
property of SourceFile
is marked as @internal
, it would be nice if this was exposed in the public api.
📃 Motivating Example
I’d like to know if a SourceFile
is of ScriptKind.JS
, so that I can make specific modifications to .js
files only.
I could simply check if the SourceFile.fileName
ends with .js
. But I’d rather make use of the same logic that is used by TypeScript for checking if a file is a JavaScript file. That way I can be sure my application and TypeScript are on the same page of what is and isn’t a JavaScript file.
💻 Use Cases
I have written a basic transformer that makes several modifications to files in a project. And now I’d like to add // @ts-nocheck
to all JavaScript files.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
I don’t see an issue with exposing this, so if you or someone else end up needing this please give another ping and we can evaluate in more detail.
Not that i can think of…