-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Import types in JS with var x = require('./mod') #22161
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
Merged
Merged
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 hidden or 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
32 changes: 32 additions & 0 deletions
32
tests/baselines/reference/varRequireFromJavascript.errors.txt
This file contains hidden or 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,32 @@ | ||
| tests/cases/conformance/salsa/use.js(1,10): error TS2304: Cannot find name 'require'. | ||
|
|
||
|
|
||
| ==== tests/cases/conformance/salsa/use.js (1 errors) ==== | ||
| var ex = require('./ex') | ||
| ~~~~~~~ | ||
| !!! error TS2304: Cannot find name 'require'. | ||
|
|
||
| // values work | ||
| var crunch = new ex.Crunch(1); | ||
| crunch.n | ||
|
|
||
|
|
||
| // types work | ||
| /** | ||
| * @param {ex.Crunch} wrap | ||
| */ | ||
| function f(wrap) { | ||
| wrap.n | ||
| } | ||
|
|
||
| ==== tests/cases/conformance/salsa/ex.js (0 errors) ==== | ||
| export class Crunch { | ||
| /** @param {number} n */ | ||
| constructor(n) { | ||
| this.n = n | ||
| } | ||
| m() { | ||
| return this.n | ||
| } | ||
| } | ||
|
|
56 changes: 56 additions & 0 deletions
56
tests/baselines/reference/varRequireFromJavascript.symbols
This file contains hidden or 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,56 @@ | ||
| === tests/cases/conformance/salsa/use.js === | ||
| var ex = require('./ex') | ||
| >ex : Symbol(ex, Decl(use.js, 0, 3)) | ||
| >'./ex' : Symbol("tests/cases/conformance/salsa/ex", Decl(ex.js, 0, 0)) | ||
|
|
||
| // values work | ||
| var crunch = new ex.Crunch(1); | ||
| >crunch : Symbol(crunch, Decl(use.js, 3, 3)) | ||
| >ex.Crunch : Symbol(Crunch, Decl(ex.js, 0, 0)) | ||
| >ex : Symbol(ex, Decl(use.js, 0, 3)) | ||
| >Crunch : Symbol(Crunch, Decl(ex.js, 0, 0)) | ||
|
|
||
| crunch.n | ||
| >crunch.n : Symbol(Crunch.n, Decl(ex.js, 2, 20)) | ||
| >crunch : Symbol(crunch, Decl(use.js, 3, 3)) | ||
| >n : Symbol(Crunch.n, Decl(ex.js, 2, 20)) | ||
|
|
||
|
|
||
| // types work | ||
| /** | ||
| * @param {ex.Crunch} wrap | ||
| */ | ||
| function f(wrap) { | ||
| >f : Symbol(f, Decl(use.js, 4, 8)) | ||
| >wrap : Symbol(wrap, Decl(use.js, 11, 11)) | ||
|
|
||
| wrap.n | ||
| >wrap.n : Symbol(Crunch.n, Decl(ex.js, 2, 20)) | ||
| >wrap : Symbol(wrap, Decl(use.js, 11, 11)) | ||
| >n : Symbol(Crunch.n, Decl(ex.js, 2, 20)) | ||
| } | ||
|
|
||
| === tests/cases/conformance/salsa/ex.js === | ||
| export class Crunch { | ||
| >Crunch : Symbol(Crunch, Decl(ex.js, 0, 0)) | ||
|
|
||
| /** @param {number} n */ | ||
| constructor(n) { | ||
| >n : Symbol(n, Decl(ex.js, 2, 16)) | ||
|
|
||
| this.n = n | ||
| >this.n : Symbol(Crunch.n, Decl(ex.js, 2, 20)) | ||
| >this : Symbol(Crunch, Decl(ex.js, 0, 0)) | ||
| >n : Symbol(Crunch.n, Decl(ex.js, 2, 20)) | ||
| >n : Symbol(n, Decl(ex.js, 2, 16)) | ||
| } | ||
| m() { | ||
| >m : Symbol(Crunch.m, Decl(ex.js, 4, 5)) | ||
|
|
||
| return this.n | ||
| >this.n : Symbol(Crunch.n, Decl(ex.js, 2, 20)) | ||
| >this : Symbol(Crunch, Decl(ex.js, 0, 0)) | ||
| >n : Symbol(Crunch.n, Decl(ex.js, 2, 20)) | ||
| } | ||
| } | ||
|
|
This file contains hidden or 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,61 @@ | ||
| === tests/cases/conformance/salsa/use.js === | ||
| var ex = require('./ex') | ||
| >ex : typeof "tests/cases/conformance/salsa/ex" | ||
| >require('./ex') : typeof "tests/cases/conformance/salsa/ex" | ||
| >require : any | ||
| >'./ex' : "./ex" | ||
|
|
||
| // values work | ||
| var crunch = new ex.Crunch(1); | ||
| >crunch : Crunch | ||
| >new ex.Crunch(1) : Crunch | ||
| >ex.Crunch : typeof Crunch | ||
| >ex : typeof "tests/cases/conformance/salsa/ex" | ||
| >Crunch : typeof Crunch | ||
| >1 : 1 | ||
|
|
||
| crunch.n | ||
| >crunch.n : number | ||
| >crunch : Crunch | ||
| >n : number | ||
|
|
||
|
|
||
| // types work | ||
| /** | ||
| * @param {ex.Crunch} wrap | ||
| */ | ||
| function f(wrap) { | ||
| >f : (wrap: Crunch) => void | ||
| >wrap : Crunch | ||
|
|
||
| wrap.n | ||
| >wrap.n : number | ||
| >wrap : Crunch | ||
| >n : number | ||
| } | ||
|
|
||
| === tests/cases/conformance/salsa/ex.js === | ||
| export class Crunch { | ||
| >Crunch : Crunch | ||
|
|
||
| /** @param {number} n */ | ||
| constructor(n) { | ||
| >n : number | ||
|
|
||
| this.n = n | ||
| >this.n = n : number | ||
| >this.n : number | ||
| >this : this | ||
| >n : number | ||
| >n : number | ||
| } | ||
| m() { | ||
| >m : () => number | ||
|
|
||
| return this.n | ||
| >this.n : number | ||
| >this : this | ||
| >n : number | ||
| } | ||
| } | ||
|
|
31 changes: 31 additions & 0 deletions
31
tests/baselines/reference/varRequireFromTypescript.errors.txt
This file contains hidden or 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 @@ | ||
| tests/cases/conformance/salsa/use.js(1,10): error TS2304: Cannot find name 'require'. | ||
|
|
||
|
|
||
| ==== tests/cases/conformance/salsa/use.js (1 errors) ==== | ||
| var ex = require('./ex') | ||
| ~~~~~~~ | ||
| !!! error TS2304: Cannot find name 'require'. | ||
|
|
||
| // values work | ||
| var crunch = new ex.Crunch(1); | ||
| crunch.n | ||
|
|
||
|
|
||
| // types work | ||
| /** | ||
| * @param {ex.Greatest} greatest | ||
| * @param {ex.Crunch} wrap | ||
| */ | ||
| function f(greatest, wrap) { | ||
| greatest.day | ||
| wrap.n | ||
| } | ||
|
|
||
| ==== tests/cases/conformance/salsa/ex.d.ts (0 errors) ==== | ||
| export type Greatest = { day: 1 } | ||
| export class Crunch { | ||
| n: number | ||
| m(): number | ||
| constructor(n: number) | ||
| } | ||
|
|
57 changes: 57 additions & 0 deletions
57
tests/baselines/reference/varRequireFromTypescript.symbols
This file contains hidden or 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,57 @@ | ||
| === tests/cases/conformance/salsa/use.js === | ||
| var ex = require('./ex') | ||
| >ex : Symbol(ex, Decl(use.js, 0, 3)) | ||
| >'./ex' : Symbol("tests/cases/conformance/salsa/ex", Decl(ex.d.ts, 0, 0)) | ||
|
|
||
| // values work | ||
| var crunch = new ex.Crunch(1); | ||
| >crunch : Symbol(crunch, Decl(use.js, 3, 3)) | ||
| >ex.Crunch : Symbol(Crunch, Decl(ex.d.ts, 0, 33)) | ||
| >ex : Symbol(ex, Decl(use.js, 0, 3)) | ||
| >Crunch : Symbol(Crunch, Decl(ex.d.ts, 0, 33)) | ||
|
|
||
| crunch.n | ||
| >crunch.n : Symbol(Crunch.n, Decl(ex.d.ts, 1, 21)) | ||
| >crunch : Symbol(crunch, Decl(use.js, 3, 3)) | ||
| >n : Symbol(Crunch.n, Decl(ex.d.ts, 1, 21)) | ||
|
|
||
|
|
||
| // types work | ||
| /** | ||
| * @param {ex.Greatest} greatest | ||
| * @param {ex.Crunch} wrap | ||
| */ | ||
| function f(greatest, wrap) { | ||
| >f : Symbol(f, Decl(use.js, 4, 8)) | ||
| >greatest : Symbol(greatest, Decl(use.js, 12, 11)) | ||
| >wrap : Symbol(wrap, Decl(use.js, 12, 20)) | ||
|
|
||
| greatest.day | ||
| >greatest.day : Symbol(day, Decl(ex.d.ts, 0, 24)) | ||
| >greatest : Symbol(greatest, Decl(use.js, 12, 11)) | ||
| >day : Symbol(day, Decl(ex.d.ts, 0, 24)) | ||
|
|
||
| wrap.n | ||
| >wrap.n : Symbol(Crunch.n, Decl(ex.d.ts, 1, 21)) | ||
| >wrap : Symbol(wrap, Decl(use.js, 12, 20)) | ||
| >n : Symbol(Crunch.n, Decl(ex.d.ts, 1, 21)) | ||
| } | ||
|
|
||
| === tests/cases/conformance/salsa/ex.d.ts === | ||
| export type Greatest = { day: 1 } | ||
| >Greatest : Symbol(Greatest, Decl(ex.d.ts, 0, 0)) | ||
| >day : Symbol(day, Decl(ex.d.ts, 0, 24)) | ||
|
|
||
| export class Crunch { | ||
| >Crunch : Symbol(Crunch, Decl(ex.d.ts, 0, 33)) | ||
|
|
||
| n: number | ||
| >n : Symbol(Crunch.n, Decl(ex.d.ts, 1, 21)) | ||
|
|
||
| m(): number | ||
| >m : Symbol(Crunch.m, Decl(ex.d.ts, 2, 13)) | ||
|
|
||
| constructor(n: number) | ||
| >n : Symbol(n, Decl(ex.d.ts, 4, 16)) | ||
| } | ||
|
|
This file contains hidden or 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,61 @@ | ||
| === tests/cases/conformance/salsa/use.js === | ||
| var ex = require('./ex') | ||
| >ex : typeof "tests/cases/conformance/salsa/ex" | ||
| >require('./ex') : typeof "tests/cases/conformance/salsa/ex" | ||
| >require : any | ||
| >'./ex' : "./ex" | ||
|
|
||
| // values work | ||
| var crunch = new ex.Crunch(1); | ||
| >crunch : Crunch | ||
| >new ex.Crunch(1) : Crunch | ||
| >ex.Crunch : typeof Crunch | ||
| >ex : typeof "tests/cases/conformance/salsa/ex" | ||
| >Crunch : typeof Crunch | ||
| >1 : 1 | ||
|
|
||
| crunch.n | ||
| >crunch.n : number | ||
| >crunch : Crunch | ||
| >n : number | ||
|
|
||
|
|
||
| // types work | ||
| /** | ||
| * @param {ex.Greatest} greatest | ||
| * @param {ex.Crunch} wrap | ||
| */ | ||
| function f(greatest, wrap) { | ||
| >f : (greatest: { day: 1; }, wrap: Crunch) => void | ||
| >greatest : { day: 1; } | ||
| >wrap : Crunch | ||
|
|
||
| greatest.day | ||
| >greatest.day : 1 | ||
| >greatest : { day: 1; } | ||
| >day : 1 | ||
|
|
||
| wrap.n | ||
| >wrap.n : number | ||
| >wrap : Crunch | ||
| >n : number | ||
| } | ||
|
|
||
| === tests/cases/conformance/salsa/ex.d.ts === | ||
| export type Greatest = { day: 1 } | ||
| >Greatest : Greatest | ||
| >day : 1 | ||
|
|
||
| export class Crunch { | ||
| >Crunch : Crunch | ||
|
|
||
| n: number | ||
| >n : number | ||
|
|
||
| m(): number | ||
| >m : () => number | ||
|
|
||
| constructor(n: number) | ||
| >n : number | ||
| } | ||
|
|
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.
this is just a drive-by fix — you can see that the else clause will never happen based on the containing
if.