Repository navigation
Treat {} in T = {} as any in JS files
#19977
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
Wesley Wigham (weswigham)
merged 1 commit into
microsoft:master
from
weswigham:empty-curly-defaults-as-any-in-js
Nov 13, 2017
Merged
Changes from all commits
Commits
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
76 changes: 76 additions & 0 deletions
76
tests/baselines/reference/defaultPropsEmptyCurlyBecomesAnyForJs.js
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,76 @@ | ||
| //// [tests/cases/compiler/defaultPropsEmptyCurlyBecomesAnyForJs.ts] //// | ||
|
|
||
| //// [library.d.ts] | ||
| export class Foo<T = {}, U = {}> { | ||
| props: T; | ||
| state: U; | ||
| constructor(props: T, state: U); | ||
| } | ||
|
|
||
| //// [component.js] | ||
| import { Foo } from "./library"; | ||
| export class MyFoo extends Foo { | ||
| member; | ||
| } | ||
|
|
||
| //// [typed_component.ts] | ||
| import { MyFoo } from "./component"; | ||
| export class TypedFoo extends MyFoo { | ||
| constructor() { | ||
| super({x: "string", y: 42}, { value: undefined }); | ||
| this.props.x; | ||
| this.props.y; | ||
| this.state.value; | ||
| this.member; | ||
| } | ||
| } | ||
|
|
||
| //// [component.js] | ||
| "use strict"; | ||
| var __extends = (this && this.__extends) || (function () { | ||
| var extendStatics = Object.setPrototypeOf || | ||
| ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
| function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
| return function (d, b) { | ||
| extendStatics(d, b); | ||
| function __() { this.constructor = d; } | ||
| d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
| }; | ||
| })(); | ||
| exports.__esModule = true; | ||
| var library_1 = require("./library"); | ||
| var MyFoo = /** @class */ (function (_super) { | ||
| __extends(MyFoo, _super); | ||
| function MyFoo() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return MyFoo; | ||
| }(library_1.Foo)); | ||
| exports.MyFoo = MyFoo; | ||
| //// [typed_component.js] | ||
| "use strict"; | ||
| var __extends = (this && this.__extends) || (function () { | ||
| var extendStatics = Object.setPrototypeOf || | ||
| ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
| function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
| return function (d, b) { | ||
| extendStatics(d, b); | ||
| function __() { this.constructor = d; } | ||
| d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
| }; | ||
| })(); | ||
| exports.__esModule = true; | ||
| var component_1 = require("./component"); | ||
| var TypedFoo = /** @class */ (function (_super) { | ||
| __extends(TypedFoo, _super); | ||
| function TypedFoo() { | ||
| var _this = _super.call(this, { x: "string", y: 42 }, { value: undefined }) || this; | ||
| _this.props.x; | ||
| _this.props.y; | ||
| _this.state.value; | ||
| _this.member; | ||
| return _this; | ||
| } | ||
| return TypedFoo; | ||
| }(component_1.MyFoo)); | ||
| exports.TypedFoo = TypedFoo; |
70 changes: 70 additions & 0 deletions
70
tests/baselines/reference/defaultPropsEmptyCurlyBecomesAnyForJs.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,70 @@ | ||
| === tests/cases/compiler/library.d.ts === | ||
| export class Foo<T = {}, U = {}> { | ||
| >Foo : Symbol(Foo, Decl(library.d.ts, --, --)) | ||
| >T : Symbol(T, Decl(library.d.ts, --, --)) | ||
| >U : Symbol(U, Decl(library.d.ts, --, --)) | ||
|
|
||
| props: T; | ||
| >props : Symbol(Foo.props, Decl(library.d.ts, --, --)) | ||
| >T : Symbol(T, Decl(library.d.ts, --, --)) | ||
|
|
||
| state: U; | ||
| >state : Symbol(Foo.state, Decl(library.d.ts, --, --)) | ||
| >U : Symbol(U, Decl(library.d.ts, --, --)) | ||
|
|
||
| constructor(props: T, state: U); | ||
| >props : Symbol(props, Decl(library.d.ts, --, --)) | ||
| >T : Symbol(T, Decl(library.d.ts, --, --)) | ||
| >state : Symbol(state, Decl(library.d.ts, --, --)) | ||
| >U : Symbol(U, Decl(library.d.ts, --, --)) | ||
| } | ||
|
|
||
| === tests/cases/compiler/component.js === | ||
| import { Foo } from "./library"; | ||
| >Foo : Symbol(Foo, Decl(component.js, 0, 8)) | ||
|
|
||
| export class MyFoo extends Foo { | ||
| >MyFoo : Symbol(MyFoo, Decl(component.js, 0, 32)) | ||
| >Foo : Symbol(Foo, Decl(component.js, 0, 8)) | ||
|
|
||
| member; | ||
| >member : Symbol(MyFoo.member, Decl(component.js, 1, 32)) | ||
| } | ||
|
|
||
| === tests/cases/compiler/typed_component.ts === | ||
| import { MyFoo } from "./component"; | ||
| >MyFoo : Symbol(MyFoo, Decl(typed_component.ts, 0, 8)) | ||
|
|
||
| export class TypedFoo extends MyFoo { | ||
| >TypedFoo : Symbol(TypedFoo, Decl(typed_component.ts, 0, 36)) | ||
| >MyFoo : Symbol(MyFoo, Decl(typed_component.ts, 0, 8)) | ||
|
|
||
| constructor() { | ||
| super({x: "string", y: 42}, { value: undefined }); | ||
| >super : Symbol(MyFoo, Decl(component.js, 0, 32)) | ||
| >x : Symbol(x, Decl(typed_component.ts, 3, 15)) | ||
| >y : Symbol(y, Decl(typed_component.ts, 3, 27)) | ||
| >value : Symbol(value, Decl(typed_component.ts, 3, 37)) | ||
| >undefined : Symbol(undefined) | ||
|
|
||
| this.props.x; | ||
| >this.props : Symbol(Foo.props, Decl(library.d.ts, --, --)) | ||
| >this : Symbol(TypedFoo, Decl(typed_component.ts, 0, 36)) | ||
| >props : Symbol(Foo.props, Decl(library.d.ts, --, --)) | ||
|
|
||
| this.props.y; | ||
| >this.props : Symbol(Foo.props, Decl(library.d.ts, --, --)) | ||
| >this : Symbol(TypedFoo, Decl(typed_component.ts, 0, 36)) | ||
| >props : Symbol(Foo.props, Decl(library.d.ts, --, --)) | ||
|
|
||
| this.state.value; | ||
| >this.state : Symbol(Foo.state, Decl(library.d.ts, --, --)) | ||
| >this : Symbol(TypedFoo, Decl(typed_component.ts, 0, 36)) | ||
| >state : Symbol(Foo.state, Decl(library.d.ts, --, --)) | ||
|
|
||
| this.member; | ||
| >this.member : Symbol(MyFoo.member, Decl(component.js, 1, 32)) | ||
| >this : Symbol(TypedFoo, Decl(typed_component.ts, 0, 36)) | ||
| >member : Symbol(MyFoo.member, Decl(component.js, 1, 32)) | ||
| } | ||
| } |
81 changes: 81 additions & 0 deletions
81
tests/baselines/reference/defaultPropsEmptyCurlyBecomesAnyForJs.types
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,81 @@ | ||
| === tests/cases/compiler/library.d.ts === | ||
| export class Foo<T = {}, U = {}> { | ||
| >Foo : Foo<T, U> | ||
| >T : T | ||
| >U : U | ||
|
|
||
| props: T; | ||
| >props : T | ||
| >T : T | ||
|
|
||
| state: U; | ||
| >state : U | ||
| >U : U | ||
|
|
||
| constructor(props: T, state: U); | ||
| >props : T | ||
| >T : T | ||
| >state : U | ||
| >U : U | ||
| } | ||
|
|
||
| === tests/cases/compiler/component.js === | ||
| import { Foo } from "./library"; | ||
| >Foo : typeof Foo | ||
|
|
||
| export class MyFoo extends Foo { | ||
| >MyFoo : MyFoo | ||
| >Foo : Foo<any, any> | ||
|
|
||
| member; | ||
| >member : any | ||
| } | ||
|
|
||
| === tests/cases/compiler/typed_component.ts === | ||
| import { MyFoo } from "./component"; | ||
| >MyFoo : typeof MyFoo | ||
|
|
||
| export class TypedFoo extends MyFoo { | ||
| >TypedFoo : TypedFoo | ||
| >MyFoo : MyFoo | ||
|
|
||
| constructor() { | ||
| super({x: "string", y: 42}, { value: undefined }); | ||
| >super({x: "string", y: 42}, { value: undefined }) : void | ||
| >super : typeof MyFoo | ||
| >{x: "string", y: 42} : { x: string; y: number; } | ||
| >x : string | ||
| >"string" : "string" | ||
| >y : number | ||
| >42 : 42 | ||
| >{ value: undefined } : { value: undefined; } | ||
| >value : undefined | ||
| >undefined : undefined | ||
|
|
||
| this.props.x; | ||
| >this.props.x : any | ||
| >this.props : any | ||
| >this : this | ||
| >props : any | ||
| >x : any | ||
|
|
||
| this.props.y; | ||
| >this.props.y : any | ||
| >this.props : any | ||
| >this : this | ||
| >props : any | ||
| >y : any | ||
|
|
||
| this.state.value; | ||
| >this.state.value : any | ||
| >this.state : any | ||
| >this : this | ||
| >state : any | ||
| >value : any | ||
|
|
||
| this.member; | ||
| >this.member : any | ||
| >this : this | ||
| >member : any | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
tests/cases/compiler/defaultPropsEmptyCurlyBecomesAnyForJs.ts
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,26 @@ | ||
| // @allowJs: true | ||
| // @outDir: ./built | ||
| // @filename: library.d.ts | ||
| export class Foo<T = {}, U = {}> { | ||
| props: T; | ||
| state: U; | ||
| constructor(props: T, state: U); | ||
| } | ||
|
|
||
| // @filename: component.js | ||
| import { Foo } from "./library"; | ||
| export class MyFoo extends Foo { | ||
| member; | ||
| } | ||
|
|
||
| // @filename: typed_component.ts | ||
| import { MyFoo } from "./component"; | ||
| export class TypedFoo extends MyFoo { | ||
| constructor() { | ||
| super({x: "string", y: 42}, { value: undefined }); | ||
| this.props.x; | ||
| this.props.y; | ||
| this.state.value; | ||
| this.member; | ||
| } | ||
| } |
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.
would
emptyTypeLiteralTypeequality check do the trick?Uh oh!
There was an error while loading. Please reload this page.
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.
Any
{}which has an alias symbol (like inreact) would defeat that. IE,