-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
“import b from './b.ts'” is valid JavaScript, but invalid TypeScript #38546
Comments
For
Since writing For updating the documentation of |
TypeScript is not obligated to issue zero errors on all JavaScript input files, otherwise no one would use it. See other issues on allowing module resolution to find |
I had to search a lot to find a workaround: Typescript also reads It will be just simpler for everybody, if https://www.typescriptlang.org/docs/handbook/module-resolution.html talks in the “Node resolution strategy” about With a.ts: import b from './b'
console.log(b) b.ts: export default 'uuuu'
When package.json contains “type”:"module", So with https://www.typescriptlang.org/docs/handbook/module-resolution.html says nothing about this. And there are more than one typescript language interpreters. In order to make them compatible/interchangable, either |
So TS shall accept |
We don't rewrite import paths. See #35589 |
That link says 'This is the fundamental promise of TypeScript: You can take some JavaScript code, put it in a TypeScript file, and it means the same thing meant before.' which contradicts the subject of this ticket. TS needs whole program knowledge or file extensions-based conclusions get abandoned. Then the only thing for All that said, the .ts extension shall disappear, typescript input files get emacs-like headers, and tsc makes sure, that the input and output directories are distinct. Then no filename rewritings happen, the whole output is moved somewhere else. Or the extension .ts stays, but the javascript engine starts accepting it somehow (as browsers do now based on mime type). But when the import means a ts file, then having |
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow. |
Well, this is not a question. |
This has been already mentioned several times on different places, that tsc shall accept
import b from './b.ts'
as valid, despite the .ts exception, but the argument, that the input is valid JavaScript, but invalid TypeScript has never been raised.Copied from #35148 (comment):
I want to use TypeScript to check the types. But to compile the code fast I want to strip the types with
@babel/preset-typescript
.When I write in some of my files
import x from ./x.ts
tsc 3.9.2 says: “An import path cannot end with a .ts extension”, butrollup
/@rollup/plugin-babel
/@babel-preset-typescript
eat the input happy.When I write instead
import x from ./x.js
, typescript does eat the input, but rollup/@rollup/plugin-babel
/@babel/preset-typescript
cannot find the file. Likewise, when I useimport x from ./x
.This code, a.js:
b.ts:
is valid JavaScript, it just does not work in Node.JS, as the latter refuses to accept .ts file extension.
But when b.ts is delivered with the correct mime type, then this works:
Demonstration: https://mail.aegee.org/dpa/35148/file.html
To sum up,
is valid JavaScript, and tsc refuses to accept valid JavaScript.
The text was updated successfully, but these errors were encountered: