[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.
This commit is contained in:
Andrey Mikhaylov (lolmaus) 2020-05-12 23:01:33 +03:00 committed by GitHub
parent 64a00b1f51
commit 0217139d1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 8 deletions

View File

@ -226,10 +226,11 @@ const ma1: Ember.MutableArray<string> = [
];
ma1.addObject('!'); // $ExpectType string
ma1.filterBy(''); // $ExpectType NativeArray<string>
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<string | null | undefined> = ['foo', undefined, null];
me1.compact(); // $ExpectType NativeArray<string>
// Ember.Namespace
const myNs = Ember.Namespace.extend({});
// Ember.NativeArray

View File

@ -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);
}
},

View File

@ -14,13 +14,13 @@ interface Enumerable<T> {
* used by bindings and other parts of the framework to extract a single
* object if the enumerable contains only one item.
*/
firstObject: ComputedProperty<T | undefined>;
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<T | undefined>;
lastObject: T | undefined;
/**
* @deprecated Use `Enumerable#includes` instead.
*/
@ -135,7 +135,7 @@ interface Enumerable<T> {
/**
* Returns a copy of the array with all `null` and `undefined` elements removed.
*/
compact(): NativeArray<T>;
compact(): NativeArray<NonNullable<T>>;
/**
* Returns a new enumerable that excludes the passed value. The default
* implementation returns an array regardless of the receiver type.

View File

@ -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);
}
},