@@ -441,7 +441,7 @@ test.each([
441441 { initial : "{}" , parameters : "{a: 3}" , expected : { a : 3 } } ,
442442 { initial : "{a: 3}" , parameters : "{a: 5}" , expected : { a : 5 } } ,
443443 { initial : "{a: 3}" , parameters : "{b: 5},{c: 7}" , expected : { a : 3 , b : 5 , c : 7 } } ,
444- ] ) ( "Object.Assign (%p)" , ( { initial, parameters, expected } ) => {
444+ ] ) ( "Object.assign (%p)" , ( { initial, parameters, expected } ) => {
445445 const jsonResult = util . transpileAndExecute ( `
446446 return JSONStringify(Object.assign(${ initial } ,${ parameters } ));
447447 ` ) ;
@@ -517,3 +517,40 @@ test.each([
517517 }
518518 }
519519} ) ;
520+
521+ // https://github.com/Microsoft/TypeScript/pull/26149
522+ const objectFromEntriesDeclaration = `
523+ interface ObjectConstructor {
524+ fromEntries<T>(entries: ReadonlyArray<[string, T]> | Iterable<[string, T]>): Record<string, T>;
525+ fromEntries(entries: ReadonlyArray<[string, any]> | Iterable<[string, any]>): Record<string, any>;
526+ }
527+ ` ;
528+
529+ test . each ( [
530+ { entries : [ ] , expected : [ ] } ,
531+ { entries : [ [ "a" , 1 ] , [ "b" , 2 ] ] , expected : { a : 1 , b : 2 } } ,
532+ { entries : [ [ "a" , 1 ] , [ "a" , 2 ] ] , expected : { a : 2 } } ,
533+ ] ) ( "Object.fromEntries (%p)" , ( { entries, expected } ) => {
534+ const result = util . transpileAndExecute (
535+ `const obj = Object.fromEntries(${ JSON . stringify ( entries ) } );
536+ return JSONStringify(obj);` ,
537+ undefined ,
538+ undefined ,
539+ objectFromEntriesDeclaration ,
540+ ) ;
541+
542+ expect ( JSON . parse ( result ) ) . toEqual ( expected ) ;
543+ } ) ;
544+
545+ test ( "Object.fromEntries (Map)" , ( ) => {
546+ const result = util . transpileAndExecute (
547+ `const map = new Map([["foo", "bar"]]);
548+ const obj = Object.fromEntries(map);
549+ return JSONStringify(obj);` ,
550+ undefined ,
551+ undefined ,
552+ objectFromEntriesDeclaration ,
553+ ) ;
554+
555+ expect ( JSON . parse ( result ) ) . toEqual ( { foo : "bar" } ) ;
556+ } ) ;
0 commit comments