-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Don't allow .ts
to appear in an import
#9646
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
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2726,8 +2726,9 @@ namespace ts { | |
return forEach(supportedTypeScriptExtensions, extension => fileExtensionIs(fileName, extension)); | ||
} | ||
|
||
export function hasTypeScriptFileExtensionNonDts(fileName: string) { | ||
return forEach(supportedTypeScriptExtensionsNonDts, extension => fileExtensionIs(fileName, extension)); | ||
/** Return ".ts" or ".tsx" if that is the extension. */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ".d.ts"? |
||
export function tryExtractTypeScriptExtensionNonDts(fileName: string): string | undefined { | ||
return find(supportedTypeScriptExtensionsNonDts, extension => fileExtensionIs(fileName, extension)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't you want to give the same error if you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, can you add a test that imports from a file ending in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If people add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
export declare var foo;
import * as v from "./foo.d.ts";
v.foo; The current emit for "use strict";
var v = require("./foo.d.ts");
v.foo; |
||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
tests/cases/compiler/user.ts(4,15): error TS2690: Module name should not include a '.ts' extension: './m.ts'. | ||
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 errors) ==== | ||
==== tests/cases/compiler/user.ts (2 errors) ==== | ||
// '.ts' extension is OK in a reference | ||
///<reference path="./m.ts"/> | ||
///<reference path="./x.ts"/> | ||
|
||
import x from "./m.ts"; | ||
import x from "./x.ts"; | ||
~~~~~~~~ | ||
!!! error TS2690: Module name should not include a '.ts' extension: './m.ts'. | ||
!!! error TS2691: An import path should not 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. | ||
|
||
==== tests/cases/compiler/m.ts (0 errors) ==== | ||
// 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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,32 @@ | ||
//// [tests/cases/compiler/moduleResolutionNoTs.ts] //// | ||
|
||
//// [m.ts] | ||
//// [x.ts] | ||
export default 0; | ||
|
||
//// [y.tsx] | ||
export default 0; | ||
|
||
//// [user.ts] | ||
// '.ts' extension is OK in a reference | ||
///<reference path="./m.ts"/> | ||
///<reference path="./x.ts"/> | ||
|
||
import x from "./x.ts"; | ||
import y from "./y.tsx"; | ||
|
||
import x from "./m.ts"; | ||
// Making sure the suggested fixes are valid: | ||
import x2 from "./x"; | ||
import y2 from "./y"; | ||
|
||
|
||
//// [m.js] | ||
//// [x.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = 0; | ||
//// [y.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = 0; | ||
//// [user.js] | ||
// '.ts' extension is OK in a reference | ||
///<reference path="./m.ts"/> | ||
///<reference path="./x.ts"/> | ||
"use strict"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
// @filename: m.ts | ||
// @filename: x.ts | ||
export default 0; | ||
|
||
// @filename: y.tsx | ||
export default 0; | ||
|
||
// @filename: user.ts | ||
// '.ts' extension is OK in a reference | ||
///<reference path="./m.ts"/> | ||
///<reference path="./x.ts"/> | ||
|
||
import x from "./x.ts"; | ||
import y from "./y.tsx"; | ||
|
||
import x from "./m.ts"; | ||
// Making sure the suggested fixes are valid: | ||
import x2 from "./x"; | ||
import y2 from "./y"; |
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.
"cannot end with"