mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Allow untyped imports
This commit is contained in:
@@ -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());
|
||||
@@ -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();
|
||||
@@ -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";
|
||||
@@ -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";
|
||||
@@ -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;
|
||||
22
tests/cases/fourslash/untypedModuleImport.ts
Normal file
22
tests/cases/fourslash/untypedModuleImport.ts
Normal 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();
|
||||
Reference in New Issue
Block a user