Skip to content

Consider a file extension other than .ts #1003

Open

Description

@lastmjs

Hi,

I'm the author of Zwitterion, and I'm currently attempting to add support for AssemblyScript. Zwitterion's goal is to allow transpiling (to JS) or compiling (to Wasm) any language for front-end browser development. Languages are detected based on their file extension. This is very simple and allows Zwitterion to differentiate between JavaScript (.js), TypeScript (.ts), Rust (.rs), Wasm (.wasm), etc.

AssemblyScript not having its own file extension makes this rather difficult. Now, besides that use case, I think there are many other reasons why having a separate file extension for AssemblyScript makes sense. Static analysis tools and developer understanding come to mind. The ES modules spec allows for arbitrary file extensions, so this should not be a problem there. Though there is controversy over these issues, I personally think it's clear that any extension should be allowed in a module path. Deno.js has dealt with these issues, I believe creating a VS Code plugin that allows for .ts extensions (it just stops the type error). That may have changed recently, but they've been thinking this through as well.

Sorry for rambling. I hope a separate file extension for AssemblyScript will be considered. Thanks!

Activity

  1. jtenner commented on Dec 12, 2019

    @jtenner
    Contributor

    This would be useful for a language server in vscode too!

  2. dcodeIO commented on Dec 12, 2019

    @dcodeIO
    Member

    This is something we might consider in the future, but at the current state, that is without our own language server, reusing the .ts extension appears to be the best we can reasonably do to provide a good dev experience.

    There are a couple of indicators, though, that tools can use to determine what's AS code, like

    • If there's a tsconfig.json extending path/to/std/assembly.json, that's an AS directory
    • If package.json has an ascMain, that's pointing at an AS entry file inside of a directory with other AS code
    • Similarly, if package.json has an asbuild script, its subscripts point at an AS entry file
    • AS code usually lives in assembly/ if not configured otherwise
  3. lastmjs commented on Dec 12, 2019

    @lastmjs
    Author

    This is something we might consider in the future, but at the current state, that is without our own language server, reusing the .ts extension appears to be the best we can reasonably do to provide a good dev experience.

    I understand. Though, isn't it simple to instruct VS Code to treat .as files as TypeScript files? I believe it is. Seems like that would be a much simpler way to get the benefits of TypeScript's static analysis in VS Code or similar editors, and still get the benefits of having a separate extension.

  4. dcodeIO commented on Dec 12, 2019

    @dcodeIO
    Member

    Last time I checked tsc hard coded the supported file extensions and the only way to change it was to maintain a fork. That was around the time of the asc prototype, though, don't know if it changed.

  5. lastmjs commented on Dec 12, 2019

    @lastmjs
    Author

    I think it depends here on what you mean by supported file extensions. TypeScript will compile import paths with any file extension. The type checker is the only thing that has problems with extensions, and I believe that isn't too hard to fix with a simple VS Code extension. In fact, I believe Deno has already done this for .ts extensions: https://marketplace.visualstudio.com/items?itemName=justjavac.vscode-deno

    Also, I have VS Code open right now, and I instructed it to treat .as files as TypeScript.

  6. lastmjs commented on Dec 13, 2019

    @lastmjs
    Author

    I just integrated AssemblyScript here: https://github.com/lastmjs/zwitterion

    It works! But, like I said, it depends on AssemblyScript having its own file extension. For now I've chosen to go with .as. And I've experimented with VS Code a little more, I can instruct it to use .as as an indicator of being a TypeScript file, and it will save that configuration. The only major problem I see is instructing the TypeScript static analyzer to allow the .as extension, but like that Deno extension I linked to above, I don't think this should be too difficult.

    Are there other issues here?

  7. lastmjs commented on Dec 18, 2019

    @lastmjs
    Author

    Seems the ActionScript problem is a deal breaker for .as. Maybe .asc?

  8. willemneal commented on Dec 18, 2019

    @willemneal
    Contributor

    Personally don't like the idea of the extension being the same as the compiler. I wish we could incorporate Wasm somehow, but we can't use .asm and it's the only one I can think of.

    Also @dcodeIO, RocketScript would be .rs... However, if we were to change the name now would be the time. My one complaint with the current name is that it's too many syllables. Keeping with the space theme we could do Ad Astra, or Arugula (which is called rocket in the UK).

  9. MaxGraey commented on Dec 18, 2019

    @MaxGraey
    Member

    .rs reserved by Rust =)

  10. torch2424 commented on Dec 18, 2019

    @torch2424
    Contributor

    Just wanted to bring up that there is this issue as well for my context: #719

    Also, I think the Github Languages woulld be a good reference. Seems like ActionScript is already conflicting with AngelScript, thus, maybe our best bet here to move forward is open an issue with Github and see if AssemblyScript could be added to the list as .as, as that seems to be the popular option?

    As in, we ask if AssemblyScript could be: .as and .assemblyscript? 🤔

    also, cc @jayphelps as they had some really good insight here 😄

  11. dcodeIO commented on Dec 18, 2019

    @dcodeIO
    Member

    Here's a little repo showing what GitHub would make of .as. Can also be forked to see what needs to be done to make everything work both on the TS and the AS side:

    https://github.com/dcodeIO/asext

    And yeah, RocketScript/.rs was actually me trying to be funny :)

  12. torch2424 commented on Dec 18, 2019

    @torch2424
    Contributor

    Also, here are the docs for adding a new language to the Github Language detector thing: https://github.com/github/linguist/blob/master/CONTRIBUTING.md#adding-a-language 😄

    However, did some research, and @dcodeIO was correct it seems that, Typescript does not support any extension other than the ones they explicitly support: microsoft/TypeScript#10939

    I'm starting to agree with maybe .as.ts makes the most sense here? 🤔

  13. lastmjs commented on Dec 19, 2019

    @lastmjs
    Author

    @torch2424 .as.ts is not supported by TypeScript in imports either. Like I mentioned a few comments ago, it depends on what you mean by support. It seems the only support AssemblyScript needs is static analysis support in editors like Visual Studio Code or Atom. Is this correct? See Deno's solution to allowing .ts extensions in TypeScript imports: https://github.com/justjavac/vscode-deno/blob/master/README.md I don't imagine it would be too difficult to fork and extend the plugin to allow another extension, creating an AssemblyScript plugin for VS Code.

    Exactly what kind of support is needed from TypeScript? The compiler can already handle any extension, the typechecker is the only thing that has issues with extensions, which I imagine is easily fixed with plugins

  14. lastmjs commented on Dec 19, 2019

    @lastmjs
    Author

    It looks like the actual logic for fixing the .ts extension errors is here: https://github.com/justjavac/typescript-deno-plugin

    AssemblyScript will need its own language server eventually anyway, correct? Seems like a plugin for editors could be a natural way to fix these extension issues with the TypeScript type checker. I don't think we need to limit ourselves to something that ends with .ts

  15. torch2424 commented on Dec 20, 2019

    @torch2424
    Contributor

    @torch2424 .as.ts is not supported by TypeScript in imports either. Like I mentioned a few comments ago, it depends on what you mean by support.

    Oh my bad! I missed that my apologies!

    Exactly what kind of support is needed from TypeScript? The compiler can already handle any extension, the typechecker is the only thing that has issues with extensions, which I imagine is easily fixed with plugins

    Oops, maybe I was wrong then, I hadn't tried it, but found that open issue in which people couldn't use other extensionss 😂

    AssemblyScript will need its own language server eventually anyway, correct? Seems like a plugin for editors could be a natural way to fix these extension issues with the TypeScript type checker. I don't think we need to limit ourselves to something that ends with .ts

    Yeah I think that' correct, @jtenner mentioned this, and I think they'd have more background on it.

    But, if we can do ssomething in the tsconfig, such that it can use a custom extension for typescript files, I think it'd be good if we went with .as 😄

  16. 35 remaining items

  17. jtenner commented on May 16, 2020

    @jtenner
    Contributor

    We are still waiting on me to finish asconfig and I believe the --extension flag shipped with 0.10. Is that right, @dcodeIO?

  18. dcodeIO commented on May 16, 2020

    @dcodeIO
    Member

    Yes, the flag landed with 0.10.0. Usage is --extension .as for example, essentially replacing any .ts with .as. Note, however, that asc understands exactly one extension at a time currently, very likely leading to problems with external libraries using a different one. Rather an experimental feature to try things out.

  19. torch2424 commented on May 18, 2020

    @torch2424
    Contributor

    @dcodeIO Oh wow! I had no clue that had landed! Great work on that! 😄 👍

  20. munrocket commented on Oct 28, 2020

    @munrocket

    For simple project in one file works, thanks! And syntax is highlighted now.
    But with things like rollup-plugin-assemblyscript is not.

    Edit: I figured out how to fix this plugin it has outated version. PR: surma/rollup-plugin-assemblyscript#3

  21. johnnesky commented on Dec 13, 2020

    @johnnesky

    Hi, I'd like to add a use-case: portability. For the sake of re-using code between AssemblyScript and TypeScript, having the option of using the ".ts" extension is great, it means both compilers can use the same file. However, there are situations where the AssemblyScript code has to be slightly different. In such cases, it would be nice to be able to import, say, "library-name", and let the TypeScript compiler find "library-name.ts" while the AssemblyScript compiler would first look for a specialized version called "library-name.as.ts" or "library-name.as" and fall back on the ".ts" version if available. That would allow the two compilers to mostly share the same code, but load slightly different code where necessary.

    Actually what I really want is just compile-time macros, e.g. #ifdef(assemblyscript) ... #else ... #end but sadly neither compiler will support that AFAIK. :/

  22. dcodeIO commented on Dec 13, 2020

    @dcodeIO
    Member

    There are no macros like these, but in case it helps, in AS code there is a constant ASC_TARGET that is 1 when compiling to Wasm, respectively 0 when compiling to JS with the portable stdlib included. When not including the portable stdlib, it's not defined when compiling to JS. Where that's not enough, what I typically do is to add varying entry files. The compiler for example adds glue/js respectively glue/wasm depending on the target. (I also like the idea of falling back to .ts eventually, though.)

  23. munrocket commented on Dec 13, 2020

    @munrocket

    @johnnesky I am faced with exactly the same and created an issue #1533
    Probably we should think about this deeper, so I will reopen the issue.

  24. munrocket commented on Jun 8, 2021

    @munrocket

    A problem with current implementation that we can't mix code with .as and .ts
    Even if you trying to test .as code you will get troubles https://github.com/jtenner/as-pect/issues/355

  25. danon commented on Jul 26, 2024

    @danon

    Is the idea of AssemblyScript being a superset/subset of TypeScript still current? Doesn't it seam like an unnecessary dependency?

    PS: Hack developed by facebook was initially supposed to be fully compatbile with PHP, but they divereged since. Wouldn't the same happen with AS eventually?

  26. HerrCai0907 commented on Jul 28, 2024

    @HerrCai0907
    Contributor

    Is the idea of AssemblyScript being a superset/subset of TypeScript still current? Doesn't it seam like an unnecessary dependency?

    I partially agree this idea. From my perspective, I think it is in language design side that AS is subset of TS. I hope the TS dev can easily port to AS in half hour instead of learning a new language.

  27. PaperPrototype commented on Nov 14, 2025

    @PaperPrototype

    What was the reasoning behind going with “.as” when it conflicts with action script and angel script? What about “.ass” short for assembly?

  28. PaperPrototype commented on Nov 14, 2025

    @PaperPrototype

    Or even “.asss” for assembly script

  29. JairusSW commented on Nov 14, 2025

    @JairusSW
    Member

    That's pretty ass 🍑

  30. PaperPrototype commented on Nov 15, 2025

    @PaperPrototype

    I mean 😂 it could help with media coverage ¯\(ツ)/¯
    Also increases the languages memeification, which is always a bonus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions