-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Fix #13932: Change the order of overloads and allow union for Object.create
#13936
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 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
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
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,38 @@ | ||
| tests/cases/compiler/objectCreate-errors.ts(2,24): error TS2345: Argument of type '1' is not assignable to parameter of type 'object | null'. | ||
| tests/cases/compiler/objectCreate-errors.ts(3,24): error TS2345: Argument of type '"string"' is not assignable to parameter of type 'object | null'. | ||
| tests/cases/compiler/objectCreate-errors.ts(4,24): error TS2345: Argument of type 'false' is not assignable to parameter of type 'object | null'. | ||
| tests/cases/compiler/objectCreate-errors.ts(5,24): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'object | null'. | ||
| tests/cases/compiler/objectCreate-errors.ts(8,24): error TS2345: Argument of type '1' is not assignable to parameter of type 'object | null'. | ||
| tests/cases/compiler/objectCreate-errors.ts(9,24): error TS2345: Argument of type '"string"' is not assignable to parameter of type 'object | null'. | ||
| tests/cases/compiler/objectCreate-errors.ts(10,24): error TS2345: Argument of type 'false' is not assignable to parameter of type 'object | null'. | ||
| tests/cases/compiler/objectCreate-errors.ts(11,24): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'object | null'. | ||
|
|
||
|
|
||
| ==== tests/cases/compiler/objectCreate-errors.ts (8 errors) ==== | ||
|
|
||
| var e1 = Object.create(1); // Error | ||
| ~ | ||
| !!! error TS2345: Argument of type '1' is not assignable to parameter of type 'object | null'. | ||
| var e2 = Object.create("string"); // Error | ||
| ~~~~~~~~ | ||
| !!! error TS2345: Argument of type '"string"' is not assignable to parameter of type 'object | null'. | ||
| var e3 = Object.create(false); // Error | ||
| ~~~~~ | ||
| !!! error TS2345: Argument of type 'false' is not assignable to parameter of type 'object | null'. | ||
| var e4 = Object.create(undefined); // Error | ||
| ~~~~~~~~~ | ||
| !!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'object | null'. | ||
|
|
||
|
|
||
| var e5 = Object.create(1, {}); // Error | ||
| ~ | ||
| !!! error TS2345: Argument of type '1' is not assignable to parameter of type 'object | null'. | ||
| var e6 = Object.create("string", {}); // Error | ||
| ~~~~~~~~ | ||
| !!! error TS2345: Argument of type '"string"' is not assignable to parameter of type 'object | null'. | ||
| var e7 = Object.create(false, {}); // Error | ||
| ~~~~~ | ||
| !!! error TS2345: Argument of type 'false' is not assignable to parameter of type 'object | null'. | ||
| var e8 = Object.create(undefined, {}); // Error | ||
| ~~~~~~~~~ | ||
| !!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'object | null'. |
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,22 @@ | ||
| //// [objectCreate-errors.ts] | ||
|
|
||
| var e1 = Object.create(1); // Error | ||
| var e2 = Object.create("string"); // Error | ||
| var e3 = Object.create(false); // Error | ||
| var e4 = Object.create(undefined); // Error | ||
|
|
||
|
|
||
| var e5 = Object.create(1, {}); // Error | ||
| var e6 = Object.create("string", {}); // Error | ||
| var e7 = Object.create(false, {}); // Error | ||
| var e8 = Object.create(undefined, {}); // Error | ||
|
|
||
| //// [objectCreate-errors.js] | ||
| var e1 = Object.create(1); // Error | ||
| var e2 = Object.create("string"); // Error | ||
| var e3 = Object.create(false); // Error | ||
| var e4 = Object.create(undefined); // Error | ||
| var e5 = Object.create(1, {}); // Error | ||
| var e6 = Object.create("string", {}); // Error | ||
| var e7 = Object.create(false, {}); // Error | ||
| var e8 = Object.create(undefined, {}); // Error |
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,28 @@ | ||
| //// [objectCreate.ts] | ||
|
|
||
| declare var union: null | { a: number, b: string }; | ||
|
|
||
| var n = Object.create(null); // object | ||
| var t = Object.create({ a: 1, b: "" }); // {a: number, b: string } | ||
| var u = Object.create(union); // object | {a: number, b: string } | ||
| var e = Object.create({}); // {} | ||
| var o = Object.create(<object>{}); // object | ||
|
|
||
| var a = Object.create(null, {}); // any | ||
| var a = Object.create({ a: 1, b: "" }, {}); | ||
| var a = Object.create(union, {}); | ||
| var a = Object.create({}, {}); | ||
| var a = Object.create(<object>{}, {}); | ||
|
|
||
|
|
||
| //// [objectCreate.js] | ||
| var n = Object.create(null); // object | ||
| var t = Object.create({ a: 1, b: "" }); // {a: number, b: string } | ||
| var u = Object.create(union); // object | {a: number, b: string } | ||
| var e = Object.create({}); // {} | ||
| var o = Object.create({}); // object | ||
| var a = Object.create(null, {}); // any | ||
| var a = Object.create({ a: 1, b: "" }, {}); | ||
| var a = Object.create(union, {}); | ||
| var a = Object.create({}, {}); | ||
| var a = Object.create({}, {}); | ||
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,73 @@ | ||
| === tests/cases/compiler/objectCreate.ts === | ||
|
|
||
| declare var union: null | { a: number, b: string }; | ||
| >union : Symbol(union, Decl(objectCreate.ts, 1, 11)) | ||
| >a : Symbol(a, Decl(objectCreate.ts, 1, 27)) | ||
| >b : Symbol(b, Decl(objectCreate.ts, 1, 38)) | ||
|
|
||
| var n = Object.create(null); // object | ||
| >n : Symbol(n, Decl(objectCreate.ts, 3, 3)) | ||
| >Object.create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
|
|
||
| var t = Object.create({ a: 1, b: "" }); // {a: number, b: string } | ||
| >t : Symbol(t, Decl(objectCreate.ts, 4, 3)) | ||
| >Object.create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >a : Symbol(a, Decl(objectCreate.ts, 4, 23)) | ||
| >b : Symbol(b, Decl(objectCreate.ts, 4, 29)) | ||
|
|
||
| var u = Object.create(union); // object | {a: number, b: string } | ||
| >u : Symbol(u, Decl(objectCreate.ts, 5, 3)) | ||
| >Object.create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >union : Symbol(union, Decl(objectCreate.ts, 1, 11)) | ||
|
|
||
| var e = Object.create({}); // {} | ||
| >e : Symbol(e, Decl(objectCreate.ts, 6, 3)) | ||
| >Object.create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
|
|
||
| var o = Object.create(<object>{}); // object | ||
| >o : Symbol(o, Decl(objectCreate.ts, 7, 3)) | ||
| >Object.create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
|
|
||
| var a = Object.create(null, {}); // any | ||
| >a : Symbol(a, Decl(objectCreate.ts, 9, 3), Decl(objectCreate.ts, 10, 3), Decl(objectCreate.ts, 11, 3), Decl(objectCreate.ts, 12, 3), Decl(objectCreate.ts, 13, 3)) | ||
| >Object.create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
|
|
||
| var a = Object.create({ a: 1, b: "" }, {}); | ||
| >a : Symbol(a, Decl(objectCreate.ts, 9, 3), Decl(objectCreate.ts, 10, 3), Decl(objectCreate.ts, 11, 3), Decl(objectCreate.ts, 12, 3), Decl(objectCreate.ts, 13, 3)) | ||
| >Object.create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >a : Symbol(a, Decl(objectCreate.ts, 10, 23)) | ||
| >b : Symbol(b, Decl(objectCreate.ts, 10, 29)) | ||
|
|
||
| var a = Object.create(union, {}); | ||
| >a : Symbol(a, Decl(objectCreate.ts, 9, 3), Decl(objectCreate.ts, 10, 3), Decl(objectCreate.ts, 11, 3), Decl(objectCreate.ts, 12, 3), Decl(objectCreate.ts, 13, 3)) | ||
| >Object.create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >union : Symbol(union, Decl(objectCreate.ts, 1, 11)) | ||
|
|
||
| var a = Object.create({}, {}); | ||
| >a : Symbol(a, Decl(objectCreate.ts, 9, 3), Decl(objectCreate.ts, 10, 3), Decl(objectCreate.ts, 11, 3), Decl(objectCreate.ts, 12, 3), Decl(objectCreate.ts, 13, 3)) | ||
| >Object.create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
|
|
||
| var a = Object.create(<object>{}, {}); | ||
| >a : Symbol(a, Decl(objectCreate.ts, 9, 3), Decl(objectCreate.ts, 10, 3), Decl(objectCreate.ts, 11, 3), Decl(objectCreate.ts, 12, 3), Decl(objectCreate.ts, 13, 3)) | ||
| >Object.create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
| >create : Symbol(ObjectConstructor.create, Decl(lib.d.ts, --, --), Decl(lib.d.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,103 @@ | ||
| === tests/cases/compiler/objectCreate.ts === | ||
|
|
||
| declare var union: null | { a: number, b: string }; | ||
| >union : { a: number; b: string; } | null | ||
| >null : null | ||
| >a : number | ||
| >b : string | ||
|
|
||
| var n = Object.create(null); // object | ||
| >n : object | ||
| >Object.create(null) : object | ||
| >Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| >Object : ObjectConstructor | ||
| >create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| >null : null | ||
|
|
||
| var t = Object.create({ a: 1, b: "" }); // {a: number, b: string } | ||
| >t : object | { a: number; b: string; } | ||
| >Object.create({ a: 1, b: "" }) : object | { a: number; b: string; } | ||
| >Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| >Object : ObjectConstructor | ||
| >create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| >{ a: 1, b: "" } : { a: number; b: string; } | ||
| >a : number | ||
| >1 : 1 | ||
| >b : string | ||
| >"" : "" | ||
|
|
||
| var u = Object.create(union); // object | {a: number, b: string } | ||
| >u : object | { a: number; b: string; } | ||
| >Object.create(union) : object | { a: number; b: string; } | ||
| >Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| >Object : ObjectConstructor | ||
| >create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| >union : { a: number; b: string; } | null | ||
|
|
||
| var e = Object.create({}); // {} | ||
| >e : object | {} | ||
| >Object.create({}) : object | {} | ||
| >Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| >Object : ObjectConstructor | ||
| >create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| >{} : {} | ||
|
|
||
| var o = Object.create(<object>{}); // object | ||
| >o : object | ||
| >Object.create(<object>{}) : object | ||
| >Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| >Object : ObjectConstructor | ||
| >create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| ><object>{} : object | ||
| >{} : {} | ||
|
|
||
| var a = Object.create(null, {}); // any | ||
| >a : any | ||
| >Object.create(null, {}) : any | ||
| >Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| >Object : ObjectConstructor | ||
| >create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| >null : null | ||
| >{} : {} | ||
|
|
||
| var a = Object.create({ a: 1, b: "" }, {}); | ||
| >a : any | ||
| >Object.create({ a: 1, b: "" }, {}) : any | ||
| >Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| >Object : ObjectConstructor | ||
| >create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| >{ a: 1, b: "" } : { a: number; b: string; } | ||
| >a : number | ||
| >1 : 1 | ||
| >b : string | ||
| >"" : "" | ||
| >{} : {} | ||
|
|
||
| var a = Object.create(union, {}); | ||
| >a : any | ||
| >Object.create(union, {}) : any | ||
| >Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| >Object : ObjectConstructor | ||
| >create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| >union : { a: number; b: string; } | null | ||
| >{} : {} | ||
|
|
||
| var a = Object.create({}, {}); | ||
| >a : any | ||
| >Object.create({}, {}) : any | ||
| >Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| >Object : ObjectConstructor | ||
| >create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| >{} : {} | ||
| >{} : {} | ||
|
|
||
| var a = Object.create(<object>{}, {}); | ||
| >a : any | ||
| >Object.create(<object>{}, {}) : any | ||
| >Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| >Object : ObjectConstructor | ||
| >create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; } | ||
| ><object>{} : object | ||
| >{} : {} | ||
| >{} : {} | ||
|
|
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,28 @@ | ||
| //// [objectCreate2.ts] | ||
|
|
||
| declare var union: null | { a: number, b: string }; | ||
|
|
||
| var n = Object.create(null); // any | ||
| var t = Object.create({ a: 1, b: "" }); // {a: number, b: string } | ||
| var u = Object.create(union); // {a: number, b: string } | ||
| var e = Object.create({}); // {} | ||
| var o = Object.create(<object>{}); // object | ||
|
|
||
| var a = Object.create(null, {}); // any | ||
| var a = Object.create({ a: 1, b: "" }, {}); | ||
| var a = Object.create(union, {}); | ||
| var a = Object.create({}, {}); | ||
| var a = Object.create(<object>{}, {}); | ||
|
|
||
|
|
||
| //// [objectCreate2.js] | ||
| var n = Object.create(null); // any | ||
| var t = Object.create({ a: 1, b: "" }); // {a: number, b: string } | ||
| var u = Object.create(union); // {a: number, b: string } | ||
| var e = Object.create({}); // {} | ||
| var o = Object.create({}); // object | ||
| var a = Object.create(null, {}); // any | ||
| var a = Object.create({ a: 1, b: "" }, {}); | ||
| var a = Object.create(union, {}); | ||
| var a = Object.create({}, {}); | ||
| var a = Object.create({}, {}); |
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.
Isn't this a 'well defined' object, namely
{}?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.
in an input
{}is not the same asobject. object is more specific than{}. in here it does not matter. i usedobjectto avoid having a type of{} | object.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.
Makes sense. Thank you. (: