From 0217139d1ebf2346361d68b09a35974a32ab29ef Mon Sep 17 00:00:00 2001 From: "Andrey Mikhaylov (lolmaus)" Date: Tue, 12 May 2020 23:01:33 +0300 Subject: [PATCH] [ember__array] Fix compact, firstObject and lastObject (#44155) Fixes https://github.com/typed-ember/ember-cli-typescript/issues/1145 Listing C:\Code\DefinitelyTyped\ New files added to this directory will not be compressed. 136 : 136 = 1.0 to 1 .editorconfig 231 : 231 = 1.0 to 1 .gitattributes 0 : 0 = 1.0 to 1 .github 555 : 555 = 1.0 to 1 .gitignore 0 : 0 = 1.0 to 1 .history 18 : 18 = 1.0 to 1 .npmrc 7 : 7 = 1.0 to 1 .prettierignore 183 : 183 = 1.0 to 1 .prettierrc.json 189 : 189 = 1.0 to 1 .travis.yml 527 : 527 = 1.0 to 1 azure-pipelines.yml 0 : 0 = 1.0 to 1 docs 1167 : 1167 = 1.0 to 1 LICENSE 0 : 0 = 1.0 to 1 node_modules 208269 : 208269 = 1.0 to 1 notNeededPackages.json 1179 : 1179 = 1.0 to 1 package.json 31018 : 31018 = 1.0 to 1 README.cn.md 22729 : 22729 = 1.0 to 1 README.es.md 32813 : 32813 = 1.0 to 1 README.ko.md 34615 : 34615 = 1.0 to 1 README.md 38698 : 38698 = 1.0 to 1 README.ru.md 0 : 0 = 1.0 to 1 scripts 0 : 0 = 1.0 to 1 types 179466 : 179466 = 1.0 to 1 yarn.lock Of 24 files within 1 directories 0 are compressed and 24 are not compressed. 551,800 total bytes of data are stored in 551,800 bytes. The compression ratio is 1.0 to 1. --- types/ember/test/ember-module-tests.ts | 7 ++++--- types/ember/test/route.ts | 2 +- types/ember__array/-private/enumerable.d.ts | 6 +++--- types/ember__routing/test/route.ts | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/types/ember/test/ember-module-tests.ts b/types/ember/test/ember-module-tests.ts index b37882a6cc..5348779f4d 100644 --- a/types/ember/test/ember-module-tests.ts +++ b/types/ember/test/ember-module-tests.ts @@ -226,10 +226,11 @@ const ma1: Ember.MutableArray = [ ]; ma1.addObject('!'); // $ExpectType string ma1.filterBy(''); // $ExpectType NativeArray +ma1.firstObject; // $ExpectType string | undefined +ma1.lastObject; // $ExpectType string | undefined // Ember.MutableEnumerable -// tslint:disable-next-line:prefer-const -let me1: Ember.MutableEnumerable<[string]> = null as any; -me1.compact(); // $ExpectType NativeArray<[string]> +const me1: Ember.MutableEnumerable = ['foo', undefined, null]; +me1.compact(); // $ExpectType NativeArray // Ember.Namespace const myNs = Ember.Namespace.extend({}); // Ember.NativeArray diff --git a/types/ember/test/route.ts b/types/ember/test/route.ts index f1ca853267..e25e01893f 100755 --- a/types/ember/test/route.ts +++ b/types/ember/test/route.ts @@ -21,7 +21,7 @@ Route.extend({ Route.extend({ afterModel(posts: Posts, transition: Transition) { - if (posts.length === 1) { + if (posts.firstObject) { this.transitionTo('post.show', posts.firstObject); } }, diff --git a/types/ember__array/-private/enumerable.d.ts b/types/ember__array/-private/enumerable.d.ts index 636f6a9e09..e2a52d8928 100644 --- a/types/ember__array/-private/enumerable.d.ts +++ b/types/ember__array/-private/enumerable.d.ts @@ -14,13 +14,13 @@ interface Enumerable { * used by bindings and other parts of the framework to extract a single * object if the enumerable contains only one item. */ - firstObject: ComputedProperty; + firstObject: T | undefined; /** * Helper method returns the last object from a collection. If your enumerable * contains only one object, this method should always return that object. * If your enumerable is empty, this method should return `undefined`. */ - lastObject: ComputedProperty; + lastObject: T | undefined; /** * @deprecated Use `Enumerable#includes` instead. */ @@ -135,7 +135,7 @@ interface Enumerable { /** * Returns a copy of the array with all `null` and `undefined` elements removed. */ - compact(): NativeArray; + compact(): NativeArray>; /** * Returns a new enumerable that excludes the passed value. The default * implementation returns an array regardless of the receiver type. diff --git a/types/ember__routing/test/route.ts b/types/ember__routing/test/route.ts index c7e2de1bef..7b273b3656 100755 --- a/types/ember__routing/test/route.ts +++ b/types/ember__routing/test/route.ts @@ -16,7 +16,7 @@ Route.extend({ Route.extend({ afterModel(posts: Posts, transition: Transition) { - if (posts.length === 1) { + if (posts.firstObject) { this.transitionTo('post.show', posts.firstObject); } },