diff --git a/src/compiler/core.ts b/src/compiler/core.ts index d2ea69b304d..808f8a538df 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1243,6 +1243,8 @@ namespace ts { * List of supported extensions in order of file resolution precedence. */ export const supportedTypeScriptExtensions = [".ts", ".tsx", ".d.ts"]; + /** Must have ".d.ts" first because if ".ts" goes first, that will be detected as the extension instead of ".d.ts". */ + export const supportedTypescriptExtensionsForExtractExtension = [".d.ts", ".ts", ".tsx"]; export const supportedJavascriptExtensions = [".js", ".jsx"]; const allSupportedExtensions = supportedTypeScriptExtensions.concat(supportedJavascriptExtensions); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 8b32d5351ea..faf210e461f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2713,12 +2713,10 @@ namespace ts { return forEach(supportedTypeScriptExtensions, extension => fileExtensionIs(fileName, extension)); } - /** Return ".ts" or ".tsx" if that is the extension. */ + /** Return ".ts", ".d.ts", or ".tsx", if that is the extension. */ export function tryExtractTypeScriptExtension(fileName: string): string | undefined { - return find(supportedTypescriptExtensionsWithDtsFirst, extension => fileExtensionIs(fileName, extension)); + return find(supportedTypescriptExtensionsForExtractExtension, 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