TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

[Huge] Alternative File-Type extension for typescript files (.ts = mpeg-2 video)

Open adroste opened this issue 2 years ago β€’ 14 comments

Suggestion

Huge request. One thing that I don't like about typescript is the file extension itself. ".ts" was already reserved for mpeg-2 video long before anyone thought about shipping JS apps with the complexity we see today. This causes a lot of problems:

  • backup tools consider them as videos and handle them differently
  • nearly every file management/operation tool think it's a video (file recovery, search, remote access, ...)
  • file explorers think it's a video (tested on windows and macOS)
    • it opens the file in a video player per default <=> changing the default makes no sense as proper .ts (actual videos) would open up in a text editor
    • os specific features like code-preview (quicklook) stop working (see https://github.com/microsoft/TypeScript/issues/25945)
    • wrong icons
  • file patterns (e.g. web servers, custom apps) that are not optimised for the existence of typescript send typescript files with wrong mime type or apply the wrong handling per default <=> again changing this manually breaks handling of actual video files
  • even vscode is confused (see https://github.com/microsoft/TypeScript/issues/21136)

I think giving typescript the extension ".ts" was a mistake. As there is just no simple solution, we could introduce an alternative file extension like ".reallynotavideo", ".tscript", ".tsc", ... (I really don't care).

πŸ” Search Terms

  • video
  • mpeg-2

Somewhat related issue: https://github.com/microsoft/TypeScript/issues/25945

βœ… Viability Checklist

My suggestion meets these guidelines:

  • [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [x] This wouldn't change the runtime behavior of existing JavaScript code
  • [x] This could be implemented without emitting different JS based on the types of the expressions
  • [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • [x] This feature would agree with the rest of TypeScript's Design Goals.

=> However, it would still be a breaking change and could also require a lot of reconfiguration (e.g. file-patterns).

⭐ Suggestion

Introduce an "official" alternative file extension that can be used ootb for typescript files (e.g. ".tsc", ".tscript", ...).

πŸ“ƒ Motivating Example

See above

πŸ’» Use Cases

See above

adroste avatar Jan 26 '22 12:01 adroste

How does an alternative file extension benefit you? If you're consuming other people's work that uses the normal extension, you'll still have the same issues.

nmain avatar Jan 26 '22 20:01 nmain

@nmain True, to really fix this problem the whole community must adopt a new file extension. I just don't understand why they went with .ts in the first place. This is a huge problem as a file extension should tell the system or other software what the file is about. Confusing one text format with another is not that bad but creating ambiguity between a common media/video format and a code-file is (see linked issues above).

adroste avatar Jan 26 '22 20:01 adroste

This is a huge problem as a file extension should tell the system or other software what the file is about.

I can count the amount of times I encountered .ts mpeg files on one hand. Haven't heard of anyone struggling with this either. I would say this problem is rather niche, definitely not huge.

MartinJohns avatar Jan 26 '22 21:01 MartinJohns

You can use .tsx even if you're not using JSX syntax. Think of it as the "TypeScript eXtension" if that helps πŸ˜‰

RyanCavanaugh avatar Jan 26 '22 21:01 RyanCavanaugh

While using tsx is definitely an option to circumvent the problems mentioned above it breaks semantic consistency. Using tsx in a context without jsx-elements will certainly lead to confusion when sharing code as the assumption is: tsx will contain jsx elements so itβ€˜s probably code for the view.

Edit: Additionally, tsx is not a superset of ts which means that renaming ts files to tsx could be a breaking change. Unlikely because Iβ€˜m talking about edge cases but possible.

adroste avatar Jan 26 '22 21:01 adroste

If it makes you feel any better, even if we did add a brand new file extension (which we won't), we'd almost certainly eschew the ts/tsx distinction and just have it only be tsx grammar. The <T>expr syntax has largely fallen out of favor.

RyanCavanaugh avatar Jan 26 '22 22:01 RyanCavanaugh

Thanks for the statement. I just wanted to raise awareness that file extension ambiguity is a thing (and itβ€˜s annoying).

adroste avatar Jan 26 '22 22:01 adroste

This isn't a huge problem day-to-day, but it can cause problems when opening a folder full of .ts files in Windows Explorer - the file manager thinks they're all video files, puts the folder in thumbnail view, and then often spends several seconds trying to load their thumbnails, during which time the Explorer window is unresponsive. Sometimes it even crashes. It can be fixed by switching the folder to Details view, but that setting isn't always remembered.

macOS Finder sometimes stumbles in the same way.

fatcerberus avatar Jan 27 '22 05:01 fatcerberus

I feel a lot of the blame is on the file explorer applications here: If you're going to make something that implicitly opens every single file and scans every single one of them for content, it has to be bulletproof for both performance concerns and security concerns. File explorers should be incapable of crashing or performing slowly regardless of the inputs.

nmain avatar Jan 27 '22 16:01 nmain

If you're going to make something that implicitly opens every single file and scans every single one of them for content, it has to be bulletproof for both performance concerns and security concerns. File explorers should be incapable of crashing or performing slowly regardless of the inputs.

I definitely agree, but sadly we don't live in a perfect world. 😞 That being said, I was a bit surprised to find out that Finder was affected by this, since I always thought macOS used file content to determine the types of files in addition to their extensions.

fatcerberus avatar Jan 27 '22 16:01 fatcerberus

Cost me a few hours wondering why MacOS Spotlight finds text in [compiled] .js files but not in [source] .ts files. And there's no way to tell Spotlight to override/disable the mpeg interpretation of the '.ts' extension.

Can you say what potential conflict from renaming my *.ts -> *.tsx? Where/How does the <T>expr syntax apply?

jackpunt avatar Feb 28 '22 20:02 jackpunt

I was quite annoyed by Windows explorer's sluggishness with .ts and .d.ts files and found a solution that involves remapping their "file kind" to document instead of video.

More info here: https://superuser.com/questions/1304114/windows-explorer-hangs-creating-thumbnails-for-typescript-files/1733384#1733384

berniegp avatar Jul 24 '22 17:07 berniegp

I fully agree. I also have a huge problem with this because I have to choose whether to associate .ts files with a text editor or a video player. And 'open with' is not an option when dealing with archives, etc. I don't know why they would pick an extension that is already in use by another file type. It is unprofessional and extremely annoying.

pouriap avatar Sep 15 '22 05:09 pouriap

Just to voice my agreement. I understand that some people rarely encounter .ts media. But it's not rarely used as you think. ts files used a lot via internet stream. It flows like water when you view something via browser. So people who work with video/keep them will often face the drawback. I know how to set .ts as text but given I have ten thousands of ts media in my pc. It's really inconvenient to not see thumbnail of media, a huge tradeoff. This is a reason I completely avoid typescript for my personal project. If I use it, I will face day-to-day problem. I understand why some feel it niche though. A lot of my colleagues completely not program outside work hours. Their own computer (no programming) can see it as media. And office's as text.

Can explorer/finder try to smart? maybe. But we all know name check(extension) is a lot cheaper than bom check or both. That's why it's born. It's the same if some weird guy use exe/jpg/mp4 as other file type, or even byte mark. How smart and overhead it need to spend?

NPhGit avatar Nov 03 '22 19:11 NPhGit