Allow untyped imports

This commit is contained in:
Andy Hanson
2016-10-27 07:19:37 -07:00
parent b5ba3152ff
commit 4937d9c8b4
24 changed files with 402 additions and 25 deletions

View File

@@ -0,0 +1,21 @@
// @noImplicitReferences: true
// @currentDirectory: /
// This tests that importing from a JS file globally works in an untyped way.
// (Assuming we don't have `--noImplicitAny` or `--allowJs`.)
// @filename: /node_modules/foo/index.js
This file is not processed.
// @filename: /a.ts
import * as foo from "foo";
foo.bar();
// @filename: /b.ts
import foo = require("foo");
foo();
// @filename: /c.ts
import foo, { bar } from "foo";
import "./a";
import "./b";
foo(bar());

View File

@@ -0,0 +1,12 @@
// @noImplicitReferences: true
// @currentDirectory: /
// @allowJs: true
// @maxNodeModuleJsDepth: 1
// Same as untypedModuleImport.ts but with --allowJs, so the package will actually be typed.
// @filename: /node_modules/foo/index.js
exports.default = { bar() { return 0; } }
// @filename: /a.ts
import foo from "foo";
foo.bar();

View File

@@ -0,0 +1,10 @@
// @noImplicitReferences: true
// @currentDirectory: /
// @noImplicitAny: true
// This tests that `--noImplicitAny` disables untyped modules.
// @filename: /node_modules/foo/index.js
This file is not processed.
// @filename: /a.ts
import * as foo from "foo";

View File

@@ -0,0 +1,9 @@
// @noImplicitReferences: true
// @currentDirectory: /
// This tests that untyped module imports don't happen with local imports.
// @filename: /foo.js
This file is not processed.
// @filename: /a.ts
import * as foo from "./foo";

View File

@@ -0,0 +1,16 @@
// @noImplicitReferences: true
// @currentDirectory: /
// This tests that an ambient module declaration overrides an untyped import.
// @filename: /node_modules/foo/index.js
This file is not processed.
// @filename: /declarations.d.ts
declare module "foo" {
export const x: number;
}
// @filename: /a.ts
/// <reference path="./declarations.d.ts" />
import { x } from "foo";
x;

View File

@@ -0,0 +1,22 @@
/// <reference path='fourslash.ts' />
// @Filename: node_modules/foo/index.js
////{}
// @Filename: a.ts
////import /*foo*/[|foo|] from /*fooModule*/"foo";
////[|foo|]();
goTo.file("a.ts");
debug.printErrorList();
verify.numberOfErrorsInCurrentFile(0);
goTo.marker("fooModule");
verify.goToDefinitionIs([]);
verify.quickInfoIs('module "foo"');
verify.referencesAre([])
goTo.marker("foo");
verify.goToDefinitionIs([]);
verify.quickInfoIs("import foo");
verify.rangesReferenceEachOther();