-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Allow untyped imports #11889
Merged
Merged
Allow untyped imports #11889
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2869,6 +2869,10 @@ | |
"category": "Error", | ||
"code": 6143 | ||
}, | ||
"A package for '{0}' was found at '{1}', but is untyped. Because '--noImplicitAny' is enabled, this package must have a declaration.": { | ||
"category": "Error", | ||
"code": 6144 | ||
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. make this error code in the |
||
}, | ||
"Variable '{0}' implicitly has an '{1}' type.": { | ||
"category": "Error", | ||
"code": 7005 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//// [tests/cases/conformance/moduleResolution/untypedModuleImport.ts] //// | ||
|
||
//// [index.js] | ||
// This tests that importing from a JS file globally works in an untyped way. | ||
// (Assuming we don't have `--noImplicitAny` or `--allowJs`.) | ||
|
||
This file is not processed. | ||
|
||
//// [a.ts] | ||
import * as foo from "foo"; | ||
foo.bar(); | ||
|
||
//// [b.ts] | ||
import foo = require("foo"); | ||
foo(); | ||
|
||
//// [c.ts] | ||
import foo, { bar } from "foo"; | ||
import "./a"; | ||
import "./b"; | ||
foo(bar()); | ||
|
||
|
||
//// [a.js] | ||
"use strict"; | ||
var foo = require("foo"); | ||
foo.bar(); | ||
//// [b.js] | ||
"use strict"; | ||
var foo = require("foo"); | ||
foo(); | ||
//// [c.js] | ||
"use strict"; | ||
var foo_1 = require("foo"); | ||
require("./a"); | ||
require("./b"); | ||
foo_1["default"](foo_1.bar()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
=== /c.ts === | ||
import foo, { bar } from "foo"; | ||
>foo : Symbol(foo, Decl(c.ts, 0, 6)) | ||
>bar : Symbol(bar, Decl(c.ts, 0, 13)) | ||
|
||
import "./a"; | ||
import "./b"; | ||
foo(bar()); | ||
>foo : Symbol(foo, Decl(c.ts, 0, 6)) | ||
>bar : Symbol(bar, Decl(c.ts, 0, 13)) | ||
|
||
=== /a.ts === | ||
import * as foo from "foo"; | ||
>foo : Symbol(foo, Decl(a.ts, 0, 6)) | ||
|
||
foo.bar(); | ||
>foo : Symbol(foo, Decl(a.ts, 0, 6)) | ||
|
||
=== /b.ts === | ||
import foo = require("foo"); | ||
>foo : Symbol(foo, Decl(b.ts, 0, 0)) | ||
|
||
foo(); | ||
>foo : Symbol(foo, Decl(b.ts, 0, 0)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
=== /c.ts === | ||
import foo, { bar } from "foo"; | ||
>foo : any | ||
>bar : any | ||
|
||
import "./a"; | ||
import "./b"; | ||
foo(bar()); | ||
>foo(bar()) : any | ||
>foo : any | ||
>bar() : any | ||
>bar : any | ||
|
||
=== /a.ts === | ||
import * as foo from "foo"; | ||
>foo : any | ||
|
||
foo.bar(); | ||
>foo.bar() : any | ||
>foo.bar : any | ||
>foo : any | ||
>bar : any | ||
|
||
=== /b.ts === | ||
import foo = require("foo"); | ||
>foo : any | ||
|
||
foo(); | ||
>foo() : any | ||
>foo : any | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//// [tests/cases/conformance/moduleResolution/untypedModuleImport_allowJs.ts] //// | ||
|
||
//// [index.js] | ||
// Same as untypedModuleImport.ts but with --allowJs, so the package will actually be typed. | ||
|
||
exports.default = { bar() { return 0; } } | ||
|
||
//// [a.ts] | ||
import foo from "foo"; | ||
foo.bar(); | ||
|
||
|
||
//// [a.js] | ||
"use strict"; | ||
var foo_1 = require("foo"); | ||
foo_1["default"].bar(); |
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/untypedModuleImport_allowJs.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
=== /a.ts === | ||
import foo from "foo"; | ||
>foo : Symbol(foo, Decl(a.ts, 0, 6)) | ||
|
||
foo.bar(); | ||
>foo.bar : Symbol(bar, Decl(index.js, 2, 19)) | ||
>foo : Symbol(foo, Decl(a.ts, 0, 6)) | ||
>bar : Symbol(bar, Decl(index.js, 2, 19)) | ||
|
||
=== /node_modules/foo/index.js === | ||
// Same as untypedModuleImport.ts but with --allowJs, so the package will actually be typed. | ||
|
||
exports.default = { bar() { return 0; } } | ||
>exports : Symbol(default, Decl(index.js, 0, 0)) | ||
>default : Symbol(default, Decl(index.js, 0, 0)) | ||
>bar : Symbol(bar, Decl(index.js, 2, 19)) | ||
|
22 changes: 22 additions & 0 deletions
22
tests/baselines/reference/untypedModuleImport_allowJs.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
=== /a.ts === | ||
import foo from "foo"; | ||
>foo : { bar(): number; } | ||
|
||
foo.bar(); | ||
>foo.bar() : number | ||
>foo.bar : () => number | ||
>foo : { bar(): number; } | ||
>bar : () => number | ||
|
||
=== /node_modules/foo/index.js === | ||
// Same as untypedModuleImport.ts but with --allowJs, so the package will actually be typed. | ||
|
||
exports.default = { bar() { return 0; } } | ||
>exports.default = { bar() { return 0; } } : { bar(): number; } | ||
>exports.default : any | ||
>exports : any | ||
>default : any | ||
>{ bar() { return 0; } } : { bar(): number; } | ||
>bar : () => number | ||
>0 : 0 | ||
|
13 changes: 13 additions & 0 deletions
13
tests/baselines/reference/untypedModuleImport_noImplicitAny.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/a.ts(1,22): error TS6144: A package for 'foo' was found at '/node_modules/foo/index.js', but is untyped. Because '--noImplicitAny' is enabled, this package must have a declaration. | ||
|
||
|
||
==== /a.ts (1 errors) ==== | ||
import * as foo from "foo"; | ||
~~~~~ | ||
!!! error TS6144: A package for 'foo' was found at '/node_modules/foo/index.js', but is untyped. Because '--noImplicitAny' is enabled, this package must have a declaration. | ||
|
||
==== /node_modules/foo/index.js (0 errors) ==== | ||
// This tests that `--noImplicitAny` disables untyped modules. | ||
|
||
This file is not processed. | ||
|
13 changes: 13 additions & 0 deletions
13
tests/baselines/reference/untypedModuleImport_noImplicitAny.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//// [tests/cases/conformance/moduleResolution/untypedModuleImport_noImplicitAny.ts] //// | ||
|
||
//// [index.js] | ||
// This tests that `--noImplicitAny` disables untyped modules. | ||
|
||
This file is not processed. | ||
|
||
//// [a.ts] | ||
import * as foo from "foo"; | ||
|
||
|
||
//// [a.js] | ||
"use strict"; |
13 changes: 13 additions & 0 deletions
13
tests/baselines/reference/untypedModuleImport_noLocalImports.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/a.ts(1,22): error TS6143: Module './foo' was resolved to '/foo.js', but '--allowJs' is not set. | ||
|
||
|
||
==== /a.ts (1 errors) ==== | ||
import * as foo from "./foo"; | ||
~~~~~~~ | ||
!!! error TS6143: Module './foo' was resolved to '/foo.js', but '--allowJs' is not set. | ||
|
||
==== /foo.js (0 errors) ==== | ||
// This tests that untyped module imports don't happen with local imports. | ||
|
||
This file is not processed. | ||
|
13 changes: 13 additions & 0 deletions
13
tests/baselines/reference/untypedModuleImport_noLocalImports.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//// [tests/cases/conformance/moduleResolution/untypedModuleImport_noLocalImports.ts] //// | ||
|
||
//// [foo.js] | ||
// This tests that untyped module imports don't happen with local imports. | ||
|
||
This file is not processed. | ||
|
||
//// [a.ts] | ||
import * as foo from "./foo"; | ||
|
||
|
||
//// [a.js] | ||
"use strict"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
how about something more consistent with the rest of the the
--noImplicitAny
error message, e.g.:Could not find a declaration file for module '{0}'. All imports implicitly have type 'any'.
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.
How about:
"Could not find a declaration file for module '{0}'. '{1}' implicitly has an 'any' type."
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.
👍