mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 20:37:00 -05:00
added supports for 'types' compiler option
This commit is contained in:
@@ -325,6 +325,15 @@ namespace ts {
|
||||
name: "typesRoot",
|
||||
type: "string"
|
||||
},
|
||||
{
|
||||
name: "types",
|
||||
type: "list",
|
||||
element: {
|
||||
name: "types",
|
||||
type: "string"
|
||||
},
|
||||
description: Diagnostics.Type_declaration_files_to_be_included_in_compilation
|
||||
},
|
||||
{
|
||||
name: "traceResolution",
|
||||
type: "boolean",
|
||||
|
||||
@@ -2637,7 +2637,7 @@
|
||||
"category": "Error",
|
||||
"code": 6114
|
||||
},
|
||||
"======== Resolving type reference directive '{0}' from '{1}', root dir '{2}'. ========": {
|
||||
"======== Resolving type reference directive '{0}', containing file '{1}', root directory '{2}'. ========": {
|
||||
"category": "Message",
|
||||
"code": 6115
|
||||
},
|
||||
@@ -2665,10 +2665,30 @@
|
||||
"category": "Message",
|
||||
"code": 6121
|
||||
},
|
||||
"======== Resolving type reference directive '{0}' from '{1}', root dir not set. ========": {
|
||||
"======== Resolving type reference directive '{0}', containing file '{1}', root directory not set. ========": {
|
||||
"category": "Message",
|
||||
"code": 6122
|
||||
},
|
||||
"Type declaration files to be included in compilation.": {
|
||||
"category": "Message",
|
||||
"code": 6123
|
||||
},
|
||||
"Looking up in 'node_modules' folder, initial location '{0}'": {
|
||||
"category": "Message",
|
||||
"code": 6124
|
||||
},
|
||||
"Containing file is not specified and root directory cannot be determined, skipping lookup in 'node_modules' folder.": {
|
||||
"category": "Message",
|
||||
"code": 6125
|
||||
},
|
||||
"======== Resolving type reference directive '{0}', containing file not set, root directory '{1}'. ========": {
|
||||
"category": "Message",
|
||||
"code": 6126
|
||||
},
|
||||
"======== Resolving type reference directive '{0}', containing file not set, root directory not set. ========": {
|
||||
"category": "Message",
|
||||
"code": 6127
|
||||
},
|
||||
"Variable '{0}' implicitly has an '{1}' type.": {
|
||||
"category": "Error",
|
||||
"code": 7005
|
||||
|
||||
@@ -191,6 +191,11 @@ namespace ts {
|
||||
|
||||
const typeReferenceExtensions = [".d.ts"];
|
||||
|
||||
/**
|
||||
* @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.
|
||||
* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups
|
||||
* is assumed to be the same as root directory of the project.
|
||||
*/
|
||||
export function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost): ResolvedTypeReferenceDirectiveWithFailedLookupLocations {
|
||||
const traceEnabled = isTraceEnabled(options, host);
|
||||
const moduleResolutionState: ModuleResolutionState = {
|
||||
@@ -204,11 +209,21 @@ namespace ts {
|
||||
const rootDir = options.typesRoot || (options.configFilePath ? getDirectoryPath(options.configFilePath) : undefined);
|
||||
|
||||
if (traceEnabled) {
|
||||
if (rootDir !== undefined) {
|
||||
trace(host, Diagnostics.Resolving_type_reference_directive_0_from_1_root_dir_2, typeReferenceDirectiveName, containingFile, rootDir);
|
||||
if (containingFile === undefined) {
|
||||
if (rootDir === undefined) {
|
||||
trace(host, Diagnostics.Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set, typeReferenceDirectiveName);
|
||||
}
|
||||
else {
|
||||
trace(host, Diagnostics.Resolving_type_reference_directive_0_containing_file_not_set_root_directory_1, typeReferenceDirectiveName, rootDir);
|
||||
}
|
||||
}
|
||||
else {
|
||||
trace(host, Diagnostics.Resolving_type_reference_directive_0_from_1_root_dir_not_set, typeReferenceDirectiveName, containingFile);
|
||||
if (rootDir === undefined) {
|
||||
trace(host, Diagnostics.Resolving_type_reference_directive_0_containing_file_1_root_directory_not_set, typeReferenceDirectiveName, containingFile);
|
||||
}
|
||||
else {
|
||||
trace(host, Diagnostics.Resolving_type_reference_directive_0_containing_file_1_root_directory_2, typeReferenceDirectiveName, containingFile, rootDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,17 +259,33 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Resolving_from_node_modules_folder);
|
||||
let resolvedFile: string;
|
||||
let initialLocationForSecondaryLookup: string;
|
||||
if (containingFile) {
|
||||
initialLocationForSecondaryLookup = getDirectoryPath(containingFile);
|
||||
}
|
||||
// check secondary locations
|
||||
const resolvedFile = loadModuleFromNodeModules(typeReferenceDirectiveName, getDirectoryPath(containingFile), failedLookupLocations, moduleResolutionState);
|
||||
if (traceEnabled) {
|
||||
if (resolvedFile) {
|
||||
trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolvedFile, false);
|
||||
else {
|
||||
initialLocationForSecondaryLookup = rootDir;
|
||||
}
|
||||
|
||||
if (initialLocationForSecondaryLookup !== undefined) {
|
||||
// check secondary locations
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Looking_up_in_node_modules_folder_initial_location_0, initialLocationForSecondaryLookup);
|
||||
}
|
||||
else {
|
||||
trace(host, Diagnostics.Type_reference_directive_0_was_not_resolved, typeReferenceDirectiveName);
|
||||
resolvedFile = loadModuleFromNodeModules(typeReferenceDirectiveName, initialLocationForSecondaryLookup, failedLookupLocations, moduleResolutionState);
|
||||
if (traceEnabled) {
|
||||
if (resolvedFile) {
|
||||
trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolvedFile, false);
|
||||
}
|
||||
else {
|
||||
trace(host, Diagnostics.Type_reference_directive_0_was_not_resolved, typeReferenceDirectiveName);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Containing_file_is_not_specified_and_root_directory_cannot_be_determined_skipping_lookup_in_node_modules_folder);
|
||||
}
|
||||
}
|
||||
return {
|
||||
@@ -927,24 +958,15 @@ namespace ts {
|
||||
// used to track cases when two file names differ only in casing
|
||||
const filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? createFileMap<SourceFile>(fileName => fileName.toLowerCase()) : undefined;
|
||||
|
||||
if (oldProgram) {
|
||||
// check properties that can affect structure of the program or module resolution strategy
|
||||
// if any of these properties has changed - structure cannot be reused
|
||||
const oldOptions = oldProgram.getCompilerOptions();
|
||||
if ((oldOptions.module !== options.module) ||
|
||||
(oldOptions.noResolve !== options.noResolve) ||
|
||||
(oldOptions.target !== options.target) ||
|
||||
(oldOptions.noLib !== options.noLib) ||
|
||||
(oldOptions.jsx !== options.jsx) ||
|
||||
(oldOptions.allowJs !== options.allowJs) ||
|
||||
(oldOptions.rootDir !== options.rootDir) ||
|
||||
(oldOptions.typesSearchPaths !== options.typesSearchPaths) ||
|
||||
(oldOptions.configFilePath !== options.configFilePath)) {
|
||||
oldProgram = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
if (!tryReuseStructureFromOldProgram()) {
|
||||
// load type declarations specified via 'types' argument
|
||||
if (options.types && options.types.length) {
|
||||
const resolutions = resolveTypeReferenceDirectiveNamesWorker(options.types, /*containingFile*/ undefined);
|
||||
for (let i = 0; i < options.types.length; i++) {
|
||||
processTypeReferenceDirective(options.types[i], resolutions[i]);
|
||||
}
|
||||
}
|
||||
|
||||
forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false));
|
||||
// Do not process the default library if:
|
||||
// - The '--noLib' flag is used.
|
||||
@@ -1036,6 +1058,21 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check properties that can affect structure of the program or module resolution strategy
|
||||
// if any of these properties has changed - structure cannot be reused
|
||||
const oldOptions = oldProgram.getCompilerOptions();
|
||||
if ((oldOptions.module !== options.module) ||
|
||||
(oldOptions.noResolve !== options.noResolve) ||
|
||||
(oldOptions.target !== options.target) ||
|
||||
(oldOptions.noLib !== options.noLib) ||
|
||||
(oldOptions.jsx !== options.jsx) ||
|
||||
(oldOptions.allowJs !== options.allowJs) ||
|
||||
(oldOptions.rootDir !== options.rootDir) ||
|
||||
(oldOptions.typesSearchPaths !== options.typesSearchPaths) ||
|
||||
(oldOptions.configFilePath !== options.configFilePath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Debug.assert(!oldProgram.structureIsReused);
|
||||
|
||||
// there is an old program, check if we can reuse its structure
|
||||
@@ -1044,6 +1081,10 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!arrayIsEqualTo(options.types, oldOptions.types)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if program source files has changed in the way that can affect structure of the program
|
||||
const newSourceFiles: SourceFile[] = [];
|
||||
const filePaths: Path[] = [];
|
||||
@@ -1733,45 +1774,61 @@ namespace ts {
|
||||
const resolvedTypeReferenceDirective = resolutions[i];
|
||||
// store resolved type directive on the file
|
||||
setResolvedTypeReferenceDirective(file, ref.fileName, resolvedTypeReferenceDirective);
|
||||
// If we already found this library as a primary reference - nothing to do
|
||||
const previousResolution = resolvedTypeReferenceDirectives[ref.fileName];
|
||||
if (previousResolution && previousResolution.primary) {
|
||||
continue;
|
||||
}
|
||||
let saveResolution = true;
|
||||
if (resolvedTypeReferenceDirective) {
|
||||
if (resolvedTypeReferenceDirective.primary) {
|
||||
// resolved from the primary path
|
||||
processSourceFile(resolvedTypeReferenceDirective.resolvedFileName, /*isDefaultLib*/ false, /*isReference*/ true, file, ref.pos, ref.end);
|
||||
}
|
||||
else {
|
||||
// If we already resolved to this file, it must have been a secondary reference. Check file contents
|
||||
// for sameness and possibly issue an error
|
||||
if (previousResolution) {
|
||||
const otherFileText = host.readFile(resolvedTypeReferenceDirective.resolvedFileName);
|
||||
if (otherFileText !== getSourceFile(previousResolution.resolvedFileName).text) {
|
||||
fileProcessingDiagnostics.add(createFileDiagnostic(file, ref.pos, ref.end - ref.pos,
|
||||
Diagnostics.Conflicting_library_definitions_for_0_found_at_1_and_2_Copy_the_correct_file_to_the_typings_folder_to_resolve_this_conflict,
|
||||
ref.fileName,
|
||||
resolvedTypeReferenceDirective.resolvedFileName,
|
||||
previousResolution.resolvedFileName));
|
||||
}
|
||||
// don't overwrite previous resolution result
|
||||
saveResolution = false;
|
||||
}
|
||||
else {
|
||||
// First resolution of this library
|
||||
processSourceFile(resolvedTypeReferenceDirective.resolvedFileName, /*isDefaultLib*/ false, /*isReference*/ true, file, ref.pos, ref.end);
|
||||
}
|
||||
}
|
||||
processTypeReferenceDirective(ref.fileName, resolvedTypeReferenceDirective, file, ref.pos, ref.end);
|
||||
}
|
||||
}
|
||||
|
||||
function processTypeReferenceDirective(typeReferenceDirective: string, resolvedTypeReferenceDirective: ResolvedTypeReferenceDirective,
|
||||
refFile?: SourceFile, refPos?: number, refEnd?: number): void {
|
||||
|
||||
// If we already found this library as a primary reference - nothing to do
|
||||
const previousResolution = resolvedTypeReferenceDirectives[typeReferenceDirective];
|
||||
if (previousResolution && previousResolution.primary) {
|
||||
return;
|
||||
}
|
||||
let saveResolution = true;
|
||||
if (resolvedTypeReferenceDirective) {
|
||||
if (resolvedTypeReferenceDirective.primary) {
|
||||
// resolved from the primary path
|
||||
processSourceFile(resolvedTypeReferenceDirective.resolvedFileName, /*isDefaultLib*/ false, /*isReference*/ true, refFile, refPos, refEnd);
|
||||
}
|
||||
else {
|
||||
fileProcessingDiagnostics.add(createFileDiagnostic(file, ref.pos, ref.end - ref.pos, Diagnostics.Cannot_find_name_0, ref.fileName));
|
||||
// If we already resolved to this file, it must have been a secondary reference. Check file contents
|
||||
// for sameness and possibly issue an error
|
||||
if (previousResolution) {
|
||||
const otherFileText = host.readFile(resolvedTypeReferenceDirective.resolvedFileName);
|
||||
if (otherFileText !== getSourceFile(previousResolution.resolvedFileName).text) {
|
||||
fileProcessingDiagnostics.add(createDiagnostic(refFile, refPos, refEnd,
|
||||
Diagnostics.Conflicting_library_definitions_for_0_found_at_1_and_2_Copy_the_correct_file_to_the_typings_folder_to_resolve_this_conflict,
|
||||
typeReferenceDirective,
|
||||
resolvedTypeReferenceDirective.resolvedFileName,
|
||||
previousResolution.resolvedFileName
|
||||
));
|
||||
}
|
||||
// don't overwrite previous resolution result
|
||||
saveResolution = false;
|
||||
}
|
||||
else {
|
||||
// First resolution of this library
|
||||
processSourceFile(resolvedTypeReferenceDirective.resolvedFileName, /*isDefaultLib*/ false, /*isReference*/ true, refFile, refPos, refEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
fileProcessingDiagnostics.add(createDiagnostic(refFile, refPos, refEnd, Diagnostics.Cannot_find_name_0, typeReferenceDirective));
|
||||
}
|
||||
|
||||
if (saveResolution) {
|
||||
resolvedTypeReferenceDirectives[ref.fileName] = resolvedTypeReferenceDirective;
|
||||
}
|
||||
if (saveResolution) {
|
||||
resolvedTypeReferenceDirectives[typeReferenceDirective] = resolvedTypeReferenceDirective;
|
||||
}
|
||||
}
|
||||
|
||||
function createDiagnostic(refFile: SourceFile, refPos: number, refEnd: number, message: DiagnosticMessage, ...args: any[]): Diagnostic {
|
||||
if (refFile === undefined || refPos === undefined || refEnd === undefined) {
|
||||
return createCompilerDiagnostic(message, ...args);
|
||||
}
|
||||
else {
|
||||
return createFileDiagnostic(refFile, refPos, refEnd - refPos, message, ...args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2476,6 +2476,7 @@ namespace ts {
|
||||
/* @internal */
|
||||
// Path used to used to compute primary search locations
|
||||
typesRoot?: string;
|
||||
types?: string[];
|
||||
|
||||
list?: string[];
|
||||
[option: string]: CompilerOptionsValue;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[
|
||||
"======== Resolving type reference directive 'jquery' from '/consumer.ts', root dir '/'. ========",
|
||||
"======== Resolving type reference directive 'jquery', containing file '/consumer.ts', root directory '/'. ========",
|
||||
"Resolving with primary search path '/types/'",
|
||||
"File '/types/jquery/package.json' does not exist.",
|
||||
"File '/types/jquery/index.d.ts' exist - use it as a name resolution result.",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[
|
||||
"======== Resolving type reference directive 'jquery' from '/consumer.ts', root dir '/'. ========",
|
||||
"======== Resolving type reference directive 'jquery', containing file '/consumer.ts', root directory '/'. ========",
|
||||
"Resolving with primary search path '/types/'",
|
||||
"Found 'package.json' at '/types/jquery/package.json'.",
|
||||
"'package.json' has 'typings' field 'jquery.d.ts' that references '/types/jquery/jquery.d.ts'.",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[
|
||||
"======== Resolving type reference directive 'jquery' from '/a/b/consumer.ts', root dir not set. ========",
|
||||
"======== Resolving type reference directive 'jquery', containing file '/a/b/consumer.ts', root directory not set. ========",
|
||||
"Root directory cannot be determined, skipping primary search paths.",
|
||||
"Resolving from node_modules folder...",
|
||||
"Looking up in 'node_modules' folder, initial location '/a/b'",
|
||||
"File '/a/b/node_modules/jquery.ts' does not exist.",
|
||||
"File '/a/b/node_modules/jquery.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/jquery/package.json' does not exist.",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[
|
||||
"======== Resolving type reference directive 'jquery' from '/a/b/consumer.ts', root dir not set. ========",
|
||||
"======== Resolving type reference directive 'jquery', containing file '/a/b/consumer.ts', root directory not set. ========",
|
||||
"Root directory cannot be determined, skipping primary search paths.",
|
||||
"Resolving from node_modules folder...",
|
||||
"Looking up in 'node_modules' folder, initial location '/a/b'",
|
||||
"File '/a/b/node_modules/jquery.ts' does not exist.",
|
||||
"File '/a/b/node_modules/jquery.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/jquery/package.json' does not exist.",
|
||||
|
||||
12
tests/baselines/reference/library-reference-13.js
Normal file
12
tests/baselines/reference/library-reference-13.js
Normal file
@@ -0,0 +1,12 @@
|
||||
//// [tests/cases/conformance/references/library-reference-13.ts] ////
|
||||
|
||||
//// [index.d.ts]
|
||||
declare var $: { foo(): void };
|
||||
|
||||
|
||||
//// [consumer.ts]
|
||||
$.foo();
|
||||
|
||||
|
||||
//// [consumer.js]
|
||||
$.foo();
|
||||
12
tests/baselines/reference/library-reference-13.symbols
Normal file
12
tests/baselines/reference/library-reference-13.symbols
Normal file
@@ -0,0 +1,12 @@
|
||||
=== /a/b/consumer.ts ===
|
||||
$.foo();
|
||||
>$.foo : Symbol(foo, Decl(index.d.ts, 0, 16))
|
||||
>$ : Symbol($, Decl(index.d.ts, 0, 11))
|
||||
>foo : Symbol(foo, Decl(index.d.ts, 0, 16))
|
||||
|
||||
=== /a/types/jquery/index.d.ts ===
|
||||
declare var $: { foo(): void };
|
||||
>$ : Symbol($, Decl(index.d.ts, 0, 11))
|
||||
>foo : Symbol(foo, Decl(index.d.ts, 0, 16))
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"======== Resolving type reference directive 'jquery', containing file not set, root directory '/a'. ========",
|
||||
"Resolving with primary search path '/a/types/'",
|
||||
"File '/a/types/jquery/package.json' does not exist.",
|
||||
"File '/a/types/jquery/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'jquery' was successfully resolved to '/a/types/jquery/index.d.ts', primary: true. ========"
|
||||
]
|
||||
13
tests/baselines/reference/library-reference-13.types
Normal file
13
tests/baselines/reference/library-reference-13.types
Normal file
@@ -0,0 +1,13 @@
|
||||
=== /a/b/consumer.ts ===
|
||||
$.foo();
|
||||
>$.foo() : void
|
||||
>$.foo : () => void
|
||||
>$ : { foo(): void; }
|
||||
>foo : () => void
|
||||
|
||||
=== /a/types/jquery/index.d.ts ===
|
||||
declare var $: { foo(): void };
|
||||
>$ : { foo(): void; }
|
||||
>foo : () => void
|
||||
|
||||
|
||||
13
tests/baselines/reference/library-reference-14.js
Normal file
13
tests/baselines/reference/library-reference-14.js
Normal file
@@ -0,0 +1,13 @@
|
||||
//// [tests/cases/conformance/references/library-reference-14.ts] ////
|
||||
|
||||
//// [index.d.ts]
|
||||
|
||||
declare var $: { foo(): void };
|
||||
|
||||
|
||||
//// [consumer.ts]
|
||||
$.foo();
|
||||
|
||||
|
||||
//// [consumer.js]
|
||||
$.foo();
|
||||
13
tests/baselines/reference/library-reference-14.symbols
Normal file
13
tests/baselines/reference/library-reference-14.symbols
Normal file
@@ -0,0 +1,13 @@
|
||||
=== /a/b/consumer.ts ===
|
||||
$.foo();
|
||||
>$.foo : Symbol(foo, Decl(index.d.ts, 1, 16))
|
||||
>$ : Symbol($, Decl(index.d.ts, 1, 11))
|
||||
>foo : Symbol(foo, Decl(index.d.ts, 1, 16))
|
||||
|
||||
=== /a/types/jquery/index.d.ts ===
|
||||
|
||||
declare var $: { foo(): void };
|
||||
>$ : Symbol($, Decl(index.d.ts, 1, 11))
|
||||
>foo : Symbol(foo, Decl(index.d.ts, 1, 16))
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
[
|
||||
"======== Resolving type reference directive 'jquery', containing file not set, root directory '/a'. ========",
|
||||
"Resolving with primary search path '/a/types/'",
|
||||
"File '/a/types/jquery/package.json' does not exist.",
|
||||
"File '/a/types/jquery/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'jquery' was successfully resolved to '/a/types/jquery/index.d.ts', primary: true. ========"
|
||||
]
|
||||
14
tests/baselines/reference/library-reference-14.types
Normal file
14
tests/baselines/reference/library-reference-14.types
Normal file
@@ -0,0 +1,14 @@
|
||||
=== /a/b/consumer.ts ===
|
||||
$.foo();
|
||||
>$.foo() : void
|
||||
>$.foo : () => void
|
||||
>$ : { foo(): void; }
|
||||
>foo : () => void
|
||||
|
||||
=== /a/types/jquery/index.d.ts ===
|
||||
|
||||
declare var $: { foo(): void };
|
||||
>$ : { foo(): void; }
|
||||
>foo : () => void
|
||||
|
||||
|
||||
15
tests/baselines/reference/library-reference-15.errors.txt
Normal file
15
tests/baselines/reference/library-reference-15.errors.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
error TS2304: Cannot find name 'jquery'.
|
||||
/a/b/consumer.ts(1,1): error TS2304: Cannot find name '$'.
|
||||
|
||||
|
||||
!!! error TS2304: Cannot find name 'jquery'.
|
||||
==== /a/b/consumer.ts (1 errors) ====
|
||||
$.foo();
|
||||
~
|
||||
!!! error TS2304: Cannot find name '$'.
|
||||
|
||||
==== /a/types/jquery/index.d.ts (0 errors) ====
|
||||
|
||||
declare var $: { foo(): void };
|
||||
|
||||
|
||||
13
tests/baselines/reference/library-reference-15.js
Normal file
13
tests/baselines/reference/library-reference-15.js
Normal file
@@ -0,0 +1,13 @@
|
||||
//// [tests/cases/conformance/references/library-reference-15.ts] ////
|
||||
|
||||
//// [index.d.ts]
|
||||
|
||||
declare var $: { foo(): void };
|
||||
|
||||
|
||||
//// [consumer.ts]
|
||||
$.foo();
|
||||
|
||||
|
||||
//// [consumer.js]
|
||||
$.foo();
|
||||
@@ -0,0 +1,5 @@
|
||||
[
|
||||
"======== Resolving type reference directive 'jquery', containing file not set, root directory not set. ========",
|
||||
"Root directory cannot be determined, skipping primary search paths.",
|
||||
"Containing file is not specified and root directory cannot be determined, skipping lookup in 'node_modules' folder."
|
||||
]
|
||||
@@ -1,5 +1,5 @@
|
||||
[
|
||||
"======== Resolving type reference directive 'jquery' from '/consumer.ts', root dir '/'. ========",
|
||||
"======== Resolving type reference directive 'jquery', containing file '/consumer.ts', root directory '/'. ========",
|
||||
"Resolving with primary search path '/types/'",
|
||||
"Found 'package.json' at '/types/jquery/package.json'.",
|
||||
"'package.json' has 'types' field 'jquery.d.ts' that references '/types/jquery/jquery.d.ts'.",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[
|
||||
"======== Resolving type reference directive 'jquery' from '/src/consumer.ts', root dir '/src'. ========",
|
||||
"======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory '/src'. ========",
|
||||
"Resolving with primary search path '/src/types/'",
|
||||
"File '/src/types/jquery/package.json' does not exist.",
|
||||
"File '/src/types/jquery/index.d.ts' does not exist.",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[
|
||||
"======== Resolving type reference directive 'foo' from '/src/root.ts', root dir '/src'. ========",
|
||||
"======== Resolving type reference directive 'foo', containing file '/src/root.ts', root directory '/src'. ========",
|
||||
"Resolving with primary search path '/src/types/'",
|
||||
"File '/src/types/foo/package.json' does not exist.",
|
||||
"File '/src/types/foo/index.d.ts' does not exist.",
|
||||
@@ -9,7 +9,7 @@
|
||||
"Resolving with primary search path '/src/node_modules/@types/'",
|
||||
"File '/src/node_modules/@types/foo/package.json' does not exist.",
|
||||
"File '/src/node_modules/@types/foo/index.d.ts' does not exist.",
|
||||
"Resolving from node_modules folder...",
|
||||
"Looking up in 'node_modules' folder, initial location '/src'",
|
||||
"File '/src/node_modules/foo.ts' does not exist.",
|
||||
"File '/src/node_modules/foo.d.ts' does not exist.",
|
||||
"File '/src/node_modules/foo/package.json' does not exist.",
|
||||
@@ -26,7 +26,7 @@
|
||||
"File '/node_modules/foo/index.ts' does not exist.",
|
||||
"File '/node_modules/foo/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'foo' was successfully resolved to '/node_modules/foo/index.d.ts', primary: false. ========",
|
||||
"======== Resolving type reference directive 'bar' from '/src/root.ts', root dir '/src'. ========",
|
||||
"======== Resolving type reference directive 'bar', containing file '/src/root.ts', root directory '/src'. ========",
|
||||
"Resolving with primary search path '/src/types/'",
|
||||
"File '/src/types/bar/package.json' does not exist.",
|
||||
"File '/src/types/bar/index.d.ts' does not exist.",
|
||||
@@ -36,7 +36,7 @@
|
||||
"Resolving with primary search path '/src/node_modules/@types/'",
|
||||
"File '/src/node_modules/@types/bar/package.json' does not exist.",
|
||||
"File '/src/node_modules/@types/bar/index.d.ts' does not exist.",
|
||||
"Resolving from node_modules folder...",
|
||||
"Looking up in 'node_modules' folder, initial location '/src'",
|
||||
"File '/src/node_modules/bar.ts' does not exist.",
|
||||
"File '/src/node_modules/bar.d.ts' does not exist.",
|
||||
"File '/src/node_modules/bar/package.json' does not exist.",
|
||||
@@ -53,7 +53,7 @@
|
||||
"File '/node_modules/bar/index.ts' does not exist.",
|
||||
"File '/node_modules/bar/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'bar' was successfully resolved to '/node_modules/bar/index.d.ts', primary: false. ========",
|
||||
"======== Resolving type reference directive 'alpha' from '/node_modules/foo/index.d.ts', root dir '/src'. ========",
|
||||
"======== Resolving type reference directive 'alpha', containing file '/node_modules/foo/index.d.ts', root directory '/src'. ========",
|
||||
"Resolving with primary search path '/src/types/'",
|
||||
"File '/src/types/alpha/package.json' does not exist.",
|
||||
"File '/src/types/alpha/index.d.ts' does not exist.",
|
||||
@@ -63,14 +63,14 @@
|
||||
"Resolving with primary search path '/src/node_modules/@types/'",
|
||||
"File '/src/node_modules/@types/alpha/package.json' does not exist.",
|
||||
"File '/src/node_modules/@types/alpha/index.d.ts' does not exist.",
|
||||
"Resolving from node_modules folder...",
|
||||
"Looking up in 'node_modules' folder, initial location '/node_modules/foo'",
|
||||
"File '/node_modules/foo/node_modules/alpha.ts' does not exist.",
|
||||
"File '/node_modules/foo/node_modules/alpha.d.ts' does not exist.",
|
||||
"File '/node_modules/foo/node_modules/alpha/package.json' does not exist.",
|
||||
"File '/node_modules/foo/node_modules/alpha/index.ts' does not exist.",
|
||||
"File '/node_modules/foo/node_modules/alpha/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'alpha' was successfully resolved to '/node_modules/foo/node_modules/alpha/index.d.ts', primary: false. ========",
|
||||
"======== Resolving type reference directive 'alpha' from '/node_modules/bar/index.d.ts', root dir '/src'. ========",
|
||||
"======== Resolving type reference directive 'alpha', containing file '/node_modules/bar/index.d.ts', root directory '/src'. ========",
|
||||
"Resolving with primary search path '/src/types/'",
|
||||
"File '/src/types/alpha/package.json' does not exist.",
|
||||
"File '/src/types/alpha/index.d.ts' does not exist.",
|
||||
@@ -80,7 +80,7 @@
|
||||
"Resolving with primary search path '/src/node_modules/@types/'",
|
||||
"File '/src/node_modules/@types/alpha/package.json' does not exist.",
|
||||
"File '/src/node_modules/@types/alpha/index.d.ts' does not exist.",
|
||||
"Resolving from node_modules folder...",
|
||||
"Looking up in 'node_modules' folder, initial location '/node_modules/bar'",
|
||||
"File '/node_modules/bar/node_modules/alpha.ts' does not exist.",
|
||||
"File '/node_modules/bar/node_modules/alpha.d.ts' does not exist.",
|
||||
"File '/node_modules/bar/node_modules/alpha/package.json' does not exist.",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[
|
||||
"======== Resolving type reference directive 'foo' from '/src/root.ts', root dir not set. ========",
|
||||
"======== Resolving type reference directive 'foo', containing file '/src/root.ts', root directory not set. ========",
|
||||
"Root directory cannot be determined, skipping primary search paths.",
|
||||
"Resolving from node_modules folder...",
|
||||
"Looking up in 'node_modules' folder, initial location '/src'",
|
||||
"File '/src/node_modules/foo.ts' does not exist.",
|
||||
"File '/src/node_modules/foo.d.ts' does not exist.",
|
||||
"File '/src/node_modules/foo/package.json' does not exist.",
|
||||
@@ -18,9 +18,9 @@
|
||||
"File '/node_modules/foo/index.ts' does not exist.",
|
||||
"File '/node_modules/foo/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'foo' was successfully resolved to '/node_modules/foo/index.d.ts', primary: false. ========",
|
||||
"======== Resolving type reference directive 'bar' from '/src/root.ts', root dir not set. ========",
|
||||
"======== Resolving type reference directive 'bar', containing file '/src/root.ts', root directory not set. ========",
|
||||
"Root directory cannot be determined, skipping primary search paths.",
|
||||
"Resolving from node_modules folder...",
|
||||
"Looking up in 'node_modules' folder, initial location '/src'",
|
||||
"File '/src/node_modules/bar.ts' does not exist.",
|
||||
"File '/src/node_modules/bar.d.ts' does not exist.",
|
||||
"File '/src/node_modules/bar/package.json' does not exist.",
|
||||
@@ -37,18 +37,18 @@
|
||||
"File '/node_modules/bar/index.ts' does not exist.",
|
||||
"File '/node_modules/bar/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'bar' was successfully resolved to '/node_modules/bar/index.d.ts', primary: false. ========",
|
||||
"======== Resolving type reference directive 'alpha' from '/node_modules/foo/index.d.ts', root dir not set. ========",
|
||||
"======== Resolving type reference directive 'alpha', containing file '/node_modules/foo/index.d.ts', root directory not set. ========",
|
||||
"Root directory cannot be determined, skipping primary search paths.",
|
||||
"Resolving from node_modules folder...",
|
||||
"Looking up in 'node_modules' folder, initial location '/node_modules/foo'",
|
||||
"File '/node_modules/foo/node_modules/alpha.ts' does not exist.",
|
||||
"File '/node_modules/foo/node_modules/alpha.d.ts' does not exist.",
|
||||
"File '/node_modules/foo/node_modules/alpha/package.json' does not exist.",
|
||||
"File '/node_modules/foo/node_modules/alpha/index.ts' does not exist.",
|
||||
"File '/node_modules/foo/node_modules/alpha/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'alpha' was successfully resolved to '/node_modules/foo/node_modules/alpha/index.d.ts', primary: false. ========",
|
||||
"======== Resolving type reference directive 'alpha' from '/node_modules/bar/index.d.ts', root dir not set. ========",
|
||||
"======== Resolving type reference directive 'alpha', containing file '/node_modules/bar/index.d.ts', root directory not set. ========",
|
||||
"Root directory cannot be determined, skipping primary search paths.",
|
||||
"Resolving from node_modules folder...",
|
||||
"Looking up in 'node_modules' folder, initial location '/node_modules/bar'",
|
||||
"File '/node_modules/bar/node_modules/alpha.ts' does not exist.",
|
||||
"File '/node_modules/bar/node_modules/alpha.d.ts' does not exist.",
|
||||
"File '/node_modules/bar/node_modules/alpha/package.json' does not exist.",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[
|
||||
"======== Resolving type reference directive 'alpha' from '/src/foo.ts', root dir '/'. ========",
|
||||
"======== Resolving type reference directive 'alpha', containing file '/src/foo.ts', root directory '/'. ========",
|
||||
"Resolving with primary search path '/types/'",
|
||||
"File '/types/alpha/package.json' does not exist.",
|
||||
"File '/types/alpha/index.d.ts' exist - use it as a name resolution result.",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[
|
||||
"======== Resolving type reference directive 'jquery' from '/src/consumer.ts', root dir not set. ========",
|
||||
"======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory not set. ========",
|
||||
"Root directory cannot be determined, skipping primary search paths.",
|
||||
"Resolving from node_modules folder...",
|
||||
"Looking up in 'node_modules' folder, initial location '/src'",
|
||||
"File '/src/node_modules/jquery.ts' does not exist.",
|
||||
"File '/src/node_modules/jquery.d.ts' does not exist.",
|
||||
"File '/src/node_modules/jquery/package.json' does not exist.",
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
[
|
||||
"======== Resolving type reference directive 'alpha' from '/foo.ts', root dir '/'. ========",
|
||||
"======== Resolving type reference directive 'alpha', containing file '/foo.ts', root directory '/'. ========",
|
||||
"Resolving with primary search path '/types/'",
|
||||
"File '/types/alpha/package.json' does not exist.",
|
||||
"File '/types/alpha/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'alpha' was successfully resolved to '/types/alpha/index.d.ts', primary: true. ========",
|
||||
"======== Resolving type reference directive 'beta' from '/foo.ts', root dir '/'. ========",
|
||||
"======== Resolving type reference directive 'beta', containing file '/foo.ts', root directory '/'. ========",
|
||||
"Resolving with primary search path '/types/'",
|
||||
"File '/types/beta/package.json' does not exist.",
|
||||
"File '/types/beta/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'beta' was successfully resolved to '/types/beta/index.d.ts', primary: true. ========",
|
||||
"======== Resolving type reference directive 'beta' from '/types/alpha/index.d.ts', root dir '/'. ========",
|
||||
"======== Resolving type reference directive 'beta', containing file '/types/alpha/index.d.ts', root directory '/'. ========",
|
||||
"Resolving with primary search path '/types/'",
|
||||
"File '/types/beta/package.json' does not exist.",
|
||||
"File '/types/beta/index.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Type reference directive 'beta' was successfully resolved to '/types/beta/index.d.ts', primary: true. ========",
|
||||
"======== Resolving type reference directive 'alpha' from '/types/beta/index.d.ts', root dir '/'. ========",
|
||||
"======== Resolving type reference directive 'alpha', containing file '/types/beta/index.d.ts', root directory '/'. ========",
|
||||
"Resolving with primary search path '/types/'",
|
||||
"File '/types/alpha/package.json' does not exist.",
|
||||
"File '/types/alpha/index.d.ts' exist - use it as a name resolution result.",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[
|
||||
"======== Resolving type reference directive 'alpha' from '/base/src/foo.ts', root dir '/'. ========",
|
||||
"======== Resolving type reference directive 'alpha', containing file '/base/src/foo.ts', root directory '/'. ========",
|
||||
"Resolving with primary search path '/share/typelib'",
|
||||
"File '/share/typelib/alpha/package.json' does not exist.",
|
||||
"File '/share/typelib/alpha/index.d.ts' exist - use it as a name resolution result.",
|
||||
|
||||
18
tests/cases/conformance/references/library-reference-13.ts
Normal file
18
tests/cases/conformance/references/library-reference-13.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
|
||||
// load type declarations from types section of tsconfig
|
||||
|
||||
// @filename: /a/tsconfig.json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"types": [ "jquery" ]
|
||||
}
|
||||
}
|
||||
|
||||
// @filename: /a/types/jquery/index.d.ts
|
||||
declare var $: { foo(): void };
|
||||
|
||||
|
||||
// @filename: /a/b/consumer.ts
|
||||
$.foo();
|
||||
11
tests/cases/conformance/references/library-reference-14.ts
Normal file
11
tests/cases/conformance/references/library-reference-14.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
// @types: jquery
|
||||
// @typesRoot: /a
|
||||
|
||||
// @filename: /a/types/jquery/index.d.ts
|
||||
declare var $: { foo(): void };
|
||||
|
||||
|
||||
// @filename: /a/b/consumer.ts
|
||||
$.foo();
|
||||
10
tests/cases/conformance/references/library-reference-15.ts
Normal file
10
tests/cases/conformance/references/library-reference-15.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
// @types: jquery
|
||||
|
||||
// @filename: /a/types/jquery/index.d.ts
|
||||
declare var $: { foo(): void };
|
||||
|
||||
|
||||
// @filename: /a/b/consumer.ts
|
||||
$.foo();
|
||||
Reference in New Issue
Block a user