Skip to content

Commit

Permalink
Fix #14136: Make Object.create return any all the time
Browse files Browse the repository at this point in the history
  • Loading branch information
mhegazy committed Feb 18, 2017
1 parent 6b5c448 commit 1120971
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/lib/es5.d.ts
Expand Up @@ -140,7 +140,7 @@ interface ObjectConstructor {
* Creates an object that has the specified prototype or that has null prototype.
* @param o Object to use as a prototype. May be null.
*/
create<T extends object>(o: T | null): T | object;
create(o: object | null): any;

/**
* Creates an object that has the specified prototype, and that optionally contains specified properties.
Expand Down
@@ -1,11 +1,8 @@
tests/cases/compiler/assigningFromObjectToAnythingElse.ts(3,1): error TS2322: Type 'Object' is not assignable to type 'RegExp'.
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Property 'exec' is missing in type 'Object'.
tests/cases/compiler/assigningFromObjectToAnythingElse.ts(5,5): error TS2322: Type 'object | Object' is not assignable to type 'String'.
Type 'object' is not assignable to type 'String'.
Property 'charAt' is missing in type '{}'.
tests/cases/compiler/assigningFromObjectToAnythingElse.ts(6,5): error TS2322: Type 'object | Number' is not assignable to type 'String'.
Type 'object' is not assignable to type 'String'.
tests/cases/compiler/assigningFromObjectToAnythingElse.ts(5,17): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/compiler/assigningFromObjectToAnythingElse.ts(6,17): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/compiler/assigningFromObjectToAnythingElse.ts(8,5): error TS2322: Type 'Object' is not assignable to type 'Error'.
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Property 'name' is missing in type 'Object'.
Expand All @@ -21,14 +18,11 @@ tests/cases/compiler/assigningFromObjectToAnythingElse.ts(8,5): error TS2322: Ty
!!! error TS2322: Property 'exec' is missing in type 'Object'.

var a: String = Object.create<Object>("");
~
!!! error TS2322: Type 'object | Object' is not assignable to type 'String'.
!!! error TS2322: Type 'object' is not assignable to type 'String'.
!!! error TS2322: Property 'charAt' is missing in type '{}'.
~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
var c: String = Object.create<Number>(1);
~
!!! error TS2322: Type 'object | Number' is not assignable to type 'String'.
!!! error TS2322: Type 'object' is not assignable to type 'String'.
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.

var w: Error = new Object();
~
Expand Down
60 changes: 30 additions & 30 deletions tests/baselines/reference/objectCreate.types
Expand Up @@ -7,65 +7,65 @@ declare var union: null | { a: number, b: string };
>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; }
>n : any
>Object.create(null) : any
>Object.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
>create : { (o: object | null): any; (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; }
>t : any
>Object.create({ a: 1, b: "" }) : any
>Object.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
>create : { (o: object | null): any; (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; }
>u : any
>Object.create(union) : any
>Object.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
>create : { (o: object | null): any; (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; }
>e : any
>Object.create({}) : any
>Object.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
>create : { (o: object | null): any; (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; }
>o : any
>Object.create(<object>{}) : any
>Object.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
>create : { (o: object | null): any; (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.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
>create : { (o: object | null): any; (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.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
>create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
>{ a: 1, b: "" } : { a: number; b: string; }
>a : number
>1 : 1
Expand All @@ -76,27 +76,27 @@ var a = Object.create({ a: 1, b: "" }, {});
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.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
>create : { (o: object | null): any; (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.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
>create : { (o: object | null): any; (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.create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T | null): object | T; (o: object | null, properties: PropertyDescriptorMap): any; }
>create : { (o: object | null): any; (o: object | null, properties: PropertyDescriptorMap): any; }
><object>{} : object
>{} : {}
>{} : {}
Expand Down
56 changes: 28 additions & 28 deletions tests/baselines/reference/objectCreate2.types
Expand Up @@ -9,63 +9,63 @@ declare var union: null | { a: number, b: string };
var n = Object.create(null); // any
>n : any
>Object.create(null) : any
>Object.create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>create : { (o: object): any; (o: object, 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): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>t : any
>Object.create({ a: 1, b: "" }) : any
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
>{ a: 1, b: "" } : { a: number; b: string; }
>a : number
>1 : 1
>b : string
>"" : ""

var u = Object.create(union); // {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): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>u : any
>Object.create(union) : any
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
>union : { a: number; b: string; }

var e = Object.create({}); // {}
>e : object | {}
>Object.create({}) : object | {}
>Object.create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>e : any
>Object.create({}) : any
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
>{} : {}

var o = Object.create(<object>{}); // object
>o : object
>Object.create(<object>{}) : object
>Object.create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>o : any
>Object.create(<object>{}) : any
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
><object>{} : object
>{} : {}

var a = Object.create(null, {}); // any
>a : any
>Object.create(null, {}) : any
>Object.create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>create : { (o: object): any; (o: object, 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): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
>{ a: 1, b: "" } : { a: number; b: string; }
>a : number
>1 : 1
Expand All @@ -76,27 +76,27 @@ var a = Object.create({ a: 1, b: "" }, {});
var a = Object.create(union, {});
>a : any
>Object.create(union, {}) : any
>Object.create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
>union : { a: number; b: string; }
>{} : {}

var a = Object.create({}, {});
>a : any
>Object.create({}, {}) : any
>Object.create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
>{} : {}
>{} : {}

var a = Object.create(<object>{}, {});
>a : any
>Object.create(<object>{}, {}) : any
>Object.create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>Object.create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
>Object : ObjectConstructor
>create : { <T extends object>(o: T): object | T; (o: object, properties: PropertyDescriptorMap): any; }
>create : { (o: object): any; (o: object, properties: PropertyDescriptorMap): any; }
><object>{} : object
>{} : {}
>{} : {}
Expand Down

0 comments on commit 1120971

Please sign in to comment.