-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Don't allow .ts to appear in an import
#9646
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
Changes from 1 commit
448a480
a8c05a9
2821d98
0f134ed
359c8b1
3de8c22
2eb159e
8fc17af
297cb50
b452469
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2727,9 +2727,11 @@ namespace ts { | |
| } | ||
|
|
||
| /** Return ".ts" or ".tsx" if that is the extension. */ | ||
|
||
| export function tryExtractTypeScriptExtensionNonDts(fileName: string): string | undefined { | ||
| return find(supportedTypeScriptExtensionsNonDts, extension => fileExtensionIs(fileName, extension)); | ||
| export function tryExtractTypeScriptExtension(fileName: string): string | undefined { | ||
| return find(supportedTypescriptExtensionsWithDtsFirst, extension => fileExtensionIs(fileName, extension)); | ||
| } | ||
| // Must have '.d.ts' first because if '.ts' goes first, that will be detected as the extension instead of '.d.ts'. | ||
| const supportedTypescriptExtensionsWithDtsFirst = supportedTypeScriptExtensions.slice().reverse(); | ||
|
||
|
|
||
| /** | ||
| * Replace each instance of non-ascii characters by one, two, three, or four escape sequences | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,31 @@ | ||
| tests/cases/compiler/user.ts(4,15): error TS2691: An import path should not end with a '.ts' extension. Consider importing './x' instead. | ||
| tests/cases/compiler/user.ts(5,15): error TS2691: An import path should not end with a '.tsx' extension. Consider importing './y' instead. | ||
| tests/cases/compiler/user.ts(1,15): error TS2691: An import path cannot end with a '.ts' extension. Consider importing './x' instead. | ||
| tests/cases/compiler/user.ts(2,15): error TS2691: An import path cannot end with a '.tsx' extension. Consider importing './y' instead. | ||
| tests/cases/compiler/user.ts(3,15): error TS2691: An import path cannot end with a '.d.ts' extension. Consider importing './z' instead. | ||
|
|
||
|
|
||
| ==== tests/cases/compiler/user.ts (2 errors) ==== | ||
| // '.ts' extension is OK in a reference | ||
| ///<reference path="./x.ts"/> | ||
| ==== tests/cases/compiler/x.ts (0 errors) ==== | ||
| export default 0; | ||
|
|
||
| ==== tests/cases/compiler/y.tsx (0 errors) ==== | ||
| export default 0; | ||
|
|
||
| ==== tests/cases/compiler/z.d.ts (0 errors) ==== | ||
| declare const x: number; | ||
| export default x; | ||
|
|
||
| ==== tests/cases/compiler/user.ts (3 errors) ==== | ||
| import x from "./x.ts"; | ||
| ~~~~~~~~ | ||
| !!! error TS2691: An import path should not end with a '.ts' extension. Consider importing './x' instead. | ||
| !!! error TS2691: An import path cannot end with a '.ts' extension. Consider importing './x' instead. | ||
| import y from "./y.tsx"; | ||
| ~~~~~~~~~ | ||
| !!! error TS2691: An import path should not end with a '.tsx' extension. Consider importing './y' instead. | ||
| !!! error TS2691: An import path cannot end with a '.tsx' extension. Consider importing './y' instead. | ||
| import z from "./z.d.ts"; | ||
| ~~~~~~~~~~ | ||
| !!! error TS2691: An import path cannot end with a '.d.ts' extension. Consider importing './z' instead. | ||
|
|
||
| // Making sure the suggested fixes are valid: | ||
| import x2 from "./x"; | ||
| import y2 from "./y"; | ||
|
|
||
| ==== tests/cases/compiler/x.ts (0 errors) ==== | ||
| export default 0; | ||
|
|
||
| ==== tests/cases/compiler/y.tsx (0 errors) ==== | ||
| export default 0; | ||
| import z2 from "./z"; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we know that
candidateis extensionless already?tryAddingExtensionslooks like it blindly addsextto the end ofcandidateThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right, so if someone imports "foo.bar" they can get "foo.bar.ts".