Skip to content

Commit a89c62a

Browse files
committed
Fix microsoft#14136: Make Object.create return any all the time
1 parent ef25b25 commit a89c62a

File tree

4 files changed

+65
-71
lines changed

4 files changed

+65
-71
lines changed

src/lib/es5.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ interface ObjectConstructor {
140140
* Creates an object that has the specified prototype or that has null prototype.
141141
* @param o Object to use as a prototype. May be null.
142142
*/
143-
create<T extends object>(o: T | null): T | object;
143+
create(o: object | null): any;
144144

145145
/**
146146
* Creates an object that has the specified prototype, and that optionally contains specified properties.

tests/baselines/reference/assigningFromObjectToAnythingElse.errors.txt

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
tests/cases/compiler/assigningFromObjectToAnythingElse.ts(3,1): error TS2322: Type 'Object' is not assignable to type 'RegExp'.
22
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
33
Property 'exec' is missing in type 'Object'.
4-
tests/cases/compiler/assigningFromObjectToAnythingElse.ts(5,5): error TS2322: Type 'object | Object' is not assignable to type 'String'.
5-
Type 'object' is not assignable to type 'String'.
6-
Property 'charAt' is missing in type '{}'.
7-
tests/cases/compiler/assigningFromObjectToAnythingElse.ts(6,5): error TS2322: Type 'object | Number' is not assignable to type 'String'.
8-
Type 'object' is not assignable to type 'String'.
4+
tests/cases/compiler/assigningFromObjectToAnythingElse.ts(5,17): error TS2346: Supplied parameters do not match any signature of call target.
5+
tests/cases/compiler/assigningFromObjectToAnythingElse.ts(6,17): error TS2346: Supplied parameters do not match any signature of call target.
96
tests/cases/compiler/assigningFromObjectToAnythingElse.ts(8,5): error TS2322: Type 'Object' is not assignable to type 'Error'.
107
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
118
Property 'name' is missing in type 'Object'.
@@ -21,14 +18,11 @@ tests/cases/compiler/assigningFromObjectToAnythingElse.ts(8,5): error TS2322: Ty
2118
!!! error TS2322: Property 'exec' is missing in type 'Object'.
2219

2320
var a: String = Object.create<Object>("");
24-
~
25-
!!! error TS2322: Type 'object | Object' is not assignable to type 'String'.
26-
!!! error TS2322: Type 'object' is not assignable to type 'String'.
27-
!!! error TS2322: Property 'charAt' is missing in type '{}'.
21+
~~~~~~~~~~~~~~~~~~~~~~~~~
22+
!!! error TS2346: Supplied parameters do not match any signature of call target.
2823
var c: String = Object.create<Number>(1);
29-
~
30-
!!! error TS2322: Type 'object | Number' is not assignable to type 'String'.
31-
!!! error TS2322: Type 'object' is not assignable to type 'String'.
24+
~~~~~~~~~~~~~~~~~~~~~~~~
25+
!!! error TS2346: Supplied parameters do not match any signature of call target.
3226

3327
var w: Error = new Object();
3428
~

tests/baselines/reference/objectCreate.types

+30-30
Original file line numberDiff line numberDiff line change
@@ -7,65 +7,65 @@ declare var union: null | { a: number, b: string };
77
>b : string
88

99
var n = Object.create(null); // object
10-
>n : object
11-
>Object.create(null) : object
12-
>Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
10+
>n : any
11+
>Object.create(null) : any
12+
>Object.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
1313
>Object : ObjectConstructor
14-
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
14+
>create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
1515
>null : null
1616

1717
var t = Object.create({ a: 1, b: "" }); // {a: number, b: string }
18-
>t : object | { a: number; b: string; }
19-
>Object.create({ a: 1, b: "" }) : object | { a: number; b: string; }
20-
>Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
18+
>t : any
19+
>Object.create({ a: 1, b: "" }) : any
20+
>Object.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
2121
>Object : ObjectConstructor
22-
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
22+
>create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
2323
>{ a: 1, b: "" } : { a: number; b: string; }
2424
>a : number
2525
>1 : 1
2626
>b : string
2727
>"" : ""
2828

2929
var u = Object.create(union); // object | {a: number, b: string }
30-
>u : object | { a: number; b: string; }
31-
>Object.create(union) : object | { a: number; b: string; }
32-
>Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
30+
>u : any
31+
>Object.create(union) : any
32+
>Object.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
3333
>Object : ObjectConstructor
34-
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
34+
>create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
3535
>union : { a: number; b: string; } | null
3636

3737
var e = Object.create({}); // {}
38-
>e : object | {}
39-
>Object.create({}) : object | {}
40-
>Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
38+
>e : any
39+
>Object.create({}) : any
40+
>Object.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
4141
>Object : ObjectConstructor
42-
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
42+
>create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
4343
>{} : {}
4444

4545
var o = Object.create(<object>{}); // object
46-
>o : object
47-
>Object.create(<object>{}) : object
48-
>Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
46+
>o : any
47+
>Object.create(<object>{}) : any
48+
>Object.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
4949
>Object : ObjectConstructor
50-
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
50+
>create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
5151
><object>{} : object
5252
>{} : {}
5353

5454
var a = Object.create(null, {}); // any
5555
>a : any
5656
>Object.create(null, {}) : any
57-
>Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
57+
>Object.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
5858
>Object : ObjectConstructor
59-
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
59+
>create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
6060
>null : null
6161
>{} : {}
6262

6363
var a = Object.create({ a: 1, b: "" }, {});
6464
>a : any
6565
>Object.create({ a: 1, b: "" }, {}) : any
66-
>Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
66+
>Object.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
6767
>Object : ObjectConstructor
68-
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
68+
>create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
6969
>{ a: 1, b: "" } : { a: number; b: string; }
7070
>a : number
7171
>1 : 1
@@ -76,27 +76,27 @@ var a = Object.create({ a: 1, b: "" }, {});
7676
var a = Object.create(union, {});
7777
>a : any
7878
>Object.create(union, {}) : any
79-
>Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
79+
>Object.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
8080
>Object : ObjectConstructor
81-
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
81+
>create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
8282
>union : { a: number; b: string; } | null
8383
>{} : {}
8484

8585
var a = Object.create({}, {});
8686
>a : any
8787
>Object.create({}, {}) : any
88-
>Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
88+
>Object.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
8989
>Object : ObjectConstructor
90-
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
90+
>create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
9191
>{} : {}
9292
>{} : {}
9393

9494
var a = Object.create(<object>{}, {});
9595
>a : any
9696
>Object.create(<object>{}, {}) : any
97-
>Object.create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
97+
>Object.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
9898
>Object : ObjectConstructor
99-
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
99+
>create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
100100
><object>{} : object
101101
>{} : {}
102102
>{} : {}

tests/baselines/reference/objectCreate2.types

+28-28
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,63 @@ declare var union: null | { a: number, b: string };
99
var n = Object.create(null); // any
1010
>n : any
1111
>Object.create(null) : any
12-
>Object.create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
12+
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
1313
>Object : ObjectConstructor
14-
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
14+
>create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
1515
>null : null
1616

1717
var t = Object.create({ a: 1, b: "" }); // {a: number, b: string }
18-
>t : object | { a: number; b: string; }
19-
>Object.create({ a: 1, b: "" }) : object | { a: number; b: string; }
20-
>Object.create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
18+
>t : any
19+
>Object.create({ a: 1, b: "" }) : any
20+
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
2121
>Object : ObjectConstructor
22-
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
22+
>create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
2323
>{ a: 1, b: "" } : { a: number; b: string; }
2424
>a : number
2525
>1 : 1
2626
>b : string
2727
>"" : ""
2828

2929
var u = Object.create(union); // {a: number, b: string }
30-
>u : object | { a: number; b: string; }
31-
>Object.create(union) : object | { a: number; b: string; }
32-
>Object.create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
30+
>u : any
31+
>Object.create(union) : any
32+
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
3333
>Object : ObjectConstructor
34-
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
34+
>create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
3535
>union : { a: number; b: string; }
3636

3737
var e = Object.create({}); // {}
38-
>e : object | {}
39-
>Object.create({}) : object | {}
40-
>Object.create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
38+
>e : any
39+
>Object.create({}) : any
40+
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
4141
>Object : ObjectConstructor
42-
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
42+
>create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
4343
>{} : {}
4444

4545
var o = Object.create(<object>{}); // object
46-
>o : object
47-
>Object.create(<object>{}) : object
48-
>Object.create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
46+
>o : any
47+
>Object.create(<object>{}) : any
48+
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
4949
>Object : ObjectConstructor
50-
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
50+
>create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
5151
><object>{} : object
5252
>{} : {}
5353

5454
var a = Object.create(null, {}); // any
5555
>a : any
5656
>Object.create(null, {}) : any
57-
>Object.create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
57+
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
5858
>Object : ObjectConstructor
59-
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
59+
>create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
6060
>null : null
6161
>{} : {}
6262

6363
var a = Object.create({ a: 1, b: "" }, {});
6464
>a : any
6565
>Object.create({ a: 1, b: "" }, {}) : any
66-
>Object.create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
66+
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
6767
>Object : ObjectConstructor
68-
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
68+
>create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
6969
>{ a: 1, b: "" } : { a: number; b: string; }
7070
>a : number
7171
>1 : 1
@@ -76,27 +76,27 @@ var a = Object.create({ a: 1, b: "" }, {});
7676
var a = Object.create(union, {});
7777
>a : any
7878
>Object.create(union, {}) : any
79-
>Object.create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
79+
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
8080
>Object : ObjectConstructor
81-
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
81+
>create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
8282
>union : { a: number; b: string; }
8383
>{} : {}
8484

8585
var a = Object.create({}, {});
8686
>a : any
8787
>Object.create({}, {}) : any
88-
>Object.create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
88+
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
8989
>Object : ObjectConstructor
90-
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
90+
>create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
9191
>{} : {}
9292
>{} : {}
9393

9494
var a = Object.create(<object>{}, {});
9595
>a : any
9696
>Object.create(<object>{}, {}) : any
97-
>Object.create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
97+
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
9898
>Object : ObjectConstructor
99-
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
99+
>create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
100100
><object>{} : object
101101
>{} : {}
102102
>{} : {}

0 commit comments

Comments
 (0)