-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Handling input file extensions other than .ts
, .js
, .tsx
, and .jsx
#10939
Comments
That sounds like a good proposal, however there's one problem I see with scoping of these changes. If we set to treat all Perhaps instead of assigning "extensions", we could assign glob patterns? Example: {
"compilerOptions": {
"extensions" : {
"**/*.ts": "TS",
"**/*.es": "JS",
"src/**/*.js": "TS" // treat all JS files inside src as TS
}
}
} |
That's a really good idea -- it would solve the "Treat .js as JSX" problem for React Native at the same time |
With this, tsx extension could be dropped since it conflicts with the very popular 2d map editor Tiled tileset extension. http://www.mapeditor.org/ |
Declining in favor of #11158 -- the complexity of determining the grammar, emit extension, etc, especially in a loose file context, doesn't seem to outweigh the benefits relative to simply renaming the input files. |
@RyanCavanaugh really? Even saying it won't be implemented until TypeScript 3.0 would be better than closing it. :( |
The rational here is what is the use of extensions if they do not mean what they say. a file with type annotations is not For users who feel that For users who want to use other extensions than As for tooling, tsserver does support loading files in different modes already. we can add additional server configuration to mark certain extensions, e.g. This really comes down to Occam's razor. the simplest solution for tools and for users is for extensions to really mean what they are meant to mean. changing this only leads to complexity in the tooling and confusion to users. |
Not sure #11158 would help in the jspm work-flow scenario? If I load and transpile files in the browser, they are loaded with their original extension (.ts, .tsx). If I want to use JSX in one file out of 100 in a package I will have to name all 100 files .tsx since JSPM has a single default extension per package. I would rather name all files .ts since 99 files does not contain any JSX. Another way to do it would be specify the extension in the imports and not having a default extension but AFAIK tsc does not allow that either. |
Output file extension should be allowed in imports. See #4595 |
I was actually referring to input extensions, such as |
I guess the reason for the TSX extension is that the parser could not see the difference between the old style type casting and JSX? If that is the case I would suggest that if the compiler option |
I have to admit I'm a bit confused by this issue:
Put simply, there are many people and projects who want to use TypeScript as a linter/compiler, but don't want to re-architect our projects around I hope that you'll consider re-opening this issue as an umbrella, or re-opening the five issues that were closed in favor of this proposal. Thanks for all of your work on this project, have a great week. |
Do you really plan to support it? I'm emacs user so now I'm choosing between tern with .es6 files handling + bad jsx support and tide with good jsx + no .es6 files support. |
Just wanted to be clear on one bit:
This is the disagreement. If TypeScript is a superset of JavaScript (which I'm quickly learning may not be true) then .js should be parseable by the TypeScript compiler with absolutely 0 problems. In my mind, the file would become TL;DR: If TypeScript is a superset of JavaScript, then |
The modules spec allows other extensions, I don't understand why TypeScript
sees them as errors, this is causing large issues.
…On Mon, May 14, 2018, 2:42 AM Bartek ***@***.***> wrote:
I have a node bin file and I would like this file to able to consume
typscript files. Hence I'm using ts-node. However this is a problem
because tsc does not allow files without extensions (and node bin files
have no extension usually). The solution of transpiling those typescript
files to be consumed and just using node is not an easy task.
I went through this issue but it's not clear to me why this is not
possible:
tsc myFile.abc ?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#10939 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGrSj9NQ6XFzeXo1JOxz9KNH75jUTNuUks5tyVGIgaJpZM4J-GVA>
.
|
Yea, absolutely. It just not make sense. Also we are talking at least for that to be able to output different extensions not only If it is so big problem, we, both sides can make compromises - still accept only |
2018 and still we're nowhere with this :( 😞 |
Yea.. And even with 3.0 ... ❯ yarn build
yarn run v1.7.0
$ tsc --emitDeclarationOnly && babel src -d dist
src/index.js:2:5 - error TS8009: 'private' can only be used in a .ts file.
2 private x = 10
~~~~~~~
src/index.js:4:21 - error TS8010: 'types' can only be used in a .ts file.
4 setX = (newVal: number) => { this.x = newVal; }
~~~~~~
error Command failed with exit code 1. |
I made a comment earlier on this thread (which I deleted) saying how I was using the TypeScript compiler to check Flow code (cause the TypeScript tooling is so much better), and how I wished we could allow the checking of JS code with type annotations. I have to say my use case is completely useless because Flow syntax is different in some cases anyway. Also, I'm thinking if TypeScript allowed people to specify any file extension then you'd get all these insane people in the JavaScript community who would input *.js files and be like "yeah I only write standards compliant JS, I only use TS for type checking", but their code is littered with non-standard type annotations (cough Flow users cough). I think it's fantastic that TypeScript type annotations are only allowed inside *.ts, *.tsx and and *.d.ts files and I think it should always be kept that way. It makes it much better for the community. Everyone knows immediately whether they are looking at a TypeScript file, or a standard JavaScript file. GitHub statistics are correct too (has anyone ever spotted metrics on how many people are using Flow? No... because they use the same *.js extension). Also people won't try doing node myFile.js and have it blow up due to syntax errors because they had non-standard type annotations (ahem, Flow). Imagine some poor kid trying to learn javascript sees a *.js file with all these type annotations inside and is like what? Why doesn't this run? I could go on and on about the list of reasons why it would be a terrible idea for TypeScript team to support custom extensions... |
I don't have strong feelings on this issue, but I do have two cents to register. I think that eliminating file extension restrictions would open up options for people building their own tooling around This person wanted to create a webpack loader that would generate Typescript interfaces from files with (potentially) arbitrary extensions. These interfaces could then be passed along to the Typescript loader of choice. This was (arguably) more difficult/confusing than it could have been, due to a combination of the file extension restrictions and a poor error message. While Again, just two cents. I've been using TS full time for about a year, and I love it. Keep up the good work! |
Sorry if I'm duplicating someone else but not being able to move forward with simple things like this is rather frustrating |
With We are using Babel for a rather large application, and we would like to slowly add types and use the new Babel preset. We are not interested in fully "switching" to the TypeScript ecosystem, and we are currently using non-TypeScript features via Babel plugins. It makes absolutely zero sense to rename all of our JS files to ...assuming that there is no valid use-case for something that developers keep asking for is never a good thing... |
Really, there is no logic reason to do not implement this proposal. This is a must for god's sake. |
Despite a few short comings, I have decided to stay with |
Any hack way??? Something like |
noun:I verb:am verb:guessing adjective:that noun:there auxiliary verb:is adjective:no noun:way preposition:to verb:run noun:typescript preposition:on indefinite article:a noun:String? |
@RyanCavanaugh can this issue please be re-opened, since there has been a lot of really thoughtful comments since the close date regarding the utility of this (simple) functionality? Or would it be better to open a new issue? |
My scenario is to be able to port a large Adobe Animate application from javascript to typescript. Animate uses a naming convention that I probably can't change. Logic for components is stored in files called MyComponent.js and MyComponent.jsfl, where the js file is generated code containing resources and the jsfl file is the code that you write to control the component. I DO actually want the source file to be Typescript, but I can't use a ts extension because each component has TWO source files and also two different output file extensions. |
This comment has been minimized.
This comment has been minimized.
I came across this proposal while trying to setup nextjs (react) to import css modules without requiring the '.css' extension. This currently works at runtime, but tsc reports it as an error tsconfig.json
When I import the module at it works at compile/runtime, but tsc validation in vscode keeps it flagged as an error. Doing something like: Seems to me like using |
I have a situation where I want to import modules from a cache, in which all files have had their extensions removed. But I can't import them because of this limitation. |
There has been multiple requests/issues for a more flexible use of file extensions. There are a few requests, but to summarize, they fall into one of the following two buckets:
Scenarios:
.js
/.ts
extensions (such as.es
,.es6
,.ts.erb
); also have the ability to tell the compiler if they should be treated as TypeScript, JavaScript, TypeScript with JSX, or JSX. This covers Typescript compiler should compile files regardless of extension #9839, Can't find module with extension .es6 #9551, and Files with .es6 suffix are treated as TypeScript files #7926.js
/.jsx
as TypeScript files and allow type annotation / type checking in them. See Supporting type annotations and type checking in JavaScript files #7699 and "Feature can only be used in a .ts file." when switching the language mode to TypeScript in a .js file #9670. Additionally treat a.js
file as.jsx
.Today the file extensions are used in multiple places:
Proposal:
Add a new compiler option
extensions
that would be a map from a file extension to aScriptKind
entry. If provided, the extension map would override the mapping of the extension.Different parts of the compiler will need to ask for
ScriptKind
and not an extension (many already do, e.g. parsing). Fortsconfig.json
file discovery, the set of keys inextension
map would be combined with the set of known extensions.allowJs
in this model would be an alias for"extensions": { ".js" : "JS" }
. defining both properties would be an error.Declaration files are the only exemption of this rule. A
.d.ts
file meaning can not be changed, and a declaration file can only have.d.ts
extension.The text was updated successfully, but these errors were encountered: