Skip to content

Fix TypeScript with node shebang detected as JavaScript#7919

Draft
mondeja wants to merge 1 commit intogithub-linguist:mainfrom
mondeja:fix-ts-file-with-node-shebang
Draft

Fix TypeScript with node shebang detected as JavaScript#7919
mondeja wants to merge 1 commit intogithub-linguist:mainfrom
mondeja:fix-ts-file-with-node-shebang

Conversation

@mondeja
Copy link
Copy Markdown

@mondeja mondeja commented Apr 15, 2026

Fixes #7348

Description

TypeScript files with .ts extension which include "#!/usr/bin/env node or "#!/usr/bin/env node shebangs are misclassified as JavaScript files.

Checklist:

@mondeja mondeja requested a review from a team as a code owner April 15, 2026 17:45
Copy link
Copy Markdown
Member

@lildude lildude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the PR body to use the "I am adding a new extension to a language." part of the template and fill it in as if you're adding an extension.

The important part is we need real-world samples with their original filenames, and a link to the original source location and the license for legal reasons.

Please also update the test_find_by_interpreter test like in #7878 (the test wing pass until that PR is merged).

@Alhadis
Copy link
Copy Markdown
Collaborator

Alhadis commented Apr 15, 2026

Since TypeScript is a clean superset of JavaScript, how will you identify a Node executable that ends in .ts but is syntactically valid JavaScript and TypeScript? Does Node.js actually support native runtime execution of TypeScript the way Deno does?

This is a can-of-worms we've dealt with before at Linguist…

@mondeja
Copy link
Copy Markdown
Author

mondeja commented Apr 15, 2026

Since TypeScript is a clean superset of JavaScript, how will you identify a Node executable that ends in .ts but is syntactically valid JavaScript and TypeScript? Does Node.js actually support native runtime execution of TypeScript the way Deno does?

This is a can-of-worms we've dealt with before at Linguist…

You can differentiate them by the extension of the file. If it's JavasScript you can put a .js extension to the file, but if the file becomes TypeScript you can rename to use a .ts extension.

@Alhadis
Copy link
Copy Markdown
Collaborator

Alhadis commented Apr 15, 2026

@mondeja And what about Node.js executables that don't have any file extensions?

@mondeja mondeja marked this pull request as draft April 15, 2026 19:31
@mondeja
Copy link
Copy Markdown
Author

mondeja commented Apr 15, 2026

@mondeja And what about Node.js executables that don't have any file extensions?

For a file without an extension containing the #!/usr/bin/env node shebang, the result would be ambiguous (JavaScript + TypeScript), and subsequent strategies (heuristics, classifier) ​​would have to resolve it. Since TypeScript is a superset of JavaScript, a file without type annotations would likely be classified as JavaScript.

@Alhadis
Copy link
Copy Markdown
Collaborator

Alhadis commented Apr 15, 2026

… and subsequent strategies (heuristics, classifier) ​​would have to resolve it.

This is the very issue that's plagued Linguist's past attempts at getting Node.js executables containing TypeScript to be recognised as the latter. Both JavaScript and TypeScript's syntaxes are very similar, and heuristics that match dead-giveaways (like declare type foo =) aren't going to match every ambiguous file, so the most common outcome is a repository that's partially classified as TypeScript, and partially classified as JavaScript. Usually incorrectly.

Also, does node even support running TypeScript executables?

@mondeja
Copy link
Copy Markdown
Author

mondeja commented Apr 16, 2026

Also, does node even support running TypeScript executables?

Yes. Starting with Node.js 23.6 ts files can be executed running node file.ts.

This is the very issue that's plagued Linguist's past attempts at getting Node.js executables containing TypeScript to be recognised as the latter. Both JavaScript and TypeScript's syntaxes are very similar, and heuristics that match dead-giveaways (like declare type foo =) aren't going to match every ambiguous file, so the most common outcome is a repository that's partially classified as TypeScript, and partially classified as JavaScript. Usually incorrectly.

If there are bugs in linguist's classification logic we can fix them, of course. But that is out of the scope of this PR.

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.

Consider supporting .ts files with node shebang

3 participants