Skip to content

Commit

Permalink
[PR] Covariant length on ReadOnlyArray<.>
Browse files Browse the repository at this point in the history
Summary:
$ReadOnlyArray shouldn't allow `length` setting because it can mutate the array.
Closes #4266

Reviewed By: mroch

Differential Revision: D5341152

Pulled By: nmote

fbshipit-source-id: b7de22d06d8dc5e0b73cd7c7c67db4df1ce037fe
  • Loading branch information
popham authored and facebook-github-bot committed Jun 30, 2017
1 parent 09dff67 commit b815b35
Show file tree
Hide file tree
Showing 18 changed files with 345 additions and 322 deletions.
3 changes: 2 additions & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ declare class $ReadOnlyArray<+T> {
some(callbackfn: (value: T, index: number, array: $ReadOnlyArray<T>) => any, thisArg?: any): boolean;
values(): Iterator<T>;
+[key: number]: T;
length: number;
+length: number;
}

declare class Array<T> extends $ReadOnlyArray<T> {
Expand Down Expand Up @@ -275,6 +275,7 @@ declare class Array<T> extends $ReadOnlyArray<T> {


[key: number]: T;
length: number;
static (...values:Array<any>): Array<any>;
static isArray(obj: any): bool;
static from<A, B>(iter: Iterable<A>, mapFn: (elem: A, index: number) => B, thisArg?: any): Array<B>;
Expand Down
4 changes: 2 additions & 2 deletions newtests/array_literal_tuple_spread/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ export default suite(({addFile, addFiles, addCode}) => [
test.js:3
3: const arr: Array<number> = [..."hello"];
^^^^^^ number. This type is incompatible with
290: @@iterator(): Iterator<string>;
^^^^^^ string. See lib: [LIB] core.js:290
291: @@iterator(): Iterator<string>;
^^^^^^ string. See lib: [LIB] core.js:291
`,
)
.because('String is an Iterable<string>'),
Expand Down
Loading

0 comments on commit b815b35

Please sign in to comment.