Support $ReadOnlyArray
See original GitHub issueThis is a:
- Bug Report
- Feature Request
- Question
- Other
Which concerns:
- flow-runtime
- babel-plugin-flow-runtime
- flow-runtime-validators
- flow-runtime-mobx
- flow-config-parser
- The documentation website
type Thing = $ReadOnlyArray<string | number>;
const thing: Thing = [];
console.log(thing);
Output:
Thing must be an object
Expected: {
[Symbol(Symbol.iterator)]: () => Iterator<T>;
toLocaleString: () => string;
concat: <S, Item: $ReadOnlyArray<S> | S> (...items: Array<Item>) => Array<T | S>;
entries: () => Iterator<[number, T]>;
every: (callbackfn: (value: T, index: number, array: $ReadOnlyArray<T>) => any, thisArg?: any) => boolean;
filter: ((callbackfn: Boolean) => Array<$NonMaybeType<T>>) | ((callbackfn: (value: T, index: number, array: $ReadOnlyArray<T>) => any, thisArg?: any) => Array<T>);
find: (callbackfn: (value: T, index: number, array: $ReadOnlyArray<T>) => any, thisArg?: any) => T | void;
findIndex: (callbackfn: (value: T, index: number, array: $ReadOnlyArray<T>) => any, thisArg?: any) => number;
forEach: (callbackfn: (value: T, index: number, array: $ReadOnlyArray<T>) => any, thisArg?: any) => void;
includes: (searchElement: mixed, fromIndex?: number) => boolean;
indexOf: (searchElement: mixed, fromIndex?: number) => number;
join: (separator?: string) => string;
keys: () => Iterator<number>;
lastIndexOf: (searchElement: mixed, fromIndex?: number) => number;
map: <U> (callbackfn: (value: T, index: number, array: $ReadOnlyArray<T>) => U, thisArg?: any) => Array<U>;
reduce: ((callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: $ReadOnlyArray<T>) => T, initialValue: void) => T) | (<U> (callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: $ReadOnlyArray<T>) => U, initialValue: U) => U);
reduceRight: ((callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: $ReadOnlyArray<T>) => T, initialValue: void) => T) | (<U> (callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: $ReadOnlyArray<T>) => U, initialValue: U) => U);
slice: (start?: number, end?: number) => Array<T>;
some: (callbackfn: (value: T, index: number, array: $ReadOnlyArray<T>) => any, thisArg?: any) => boolean;
values: () => Iterator<T>;
length: number;
[key: number]: T;
}
Actual Value: []
Actual Type: Array<any>
IssueHunt Summary
Backers (Total: $40.00)
- issuehunt ($40.00)
Submitted pull Requests
Become a backer now!
Or submit a pull request to get the deposits!
Tips
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on IssueHunt to raise funds.
IssueHunt has been backed by the following sponsors. Become a sponsor
Issue Analytics
- State:
- Created 6 years ago
- Comments:17 (6 by maintainers)
Top Results From Across the Web
Documentation - TypeScript 3.4
TypeScript 3.4 introduces a new syntax for ReadonlyArray using a new readonly modifier ... TypeScript 3.4 also introduces new support for readonly tuples....
Read more >Support ReadonlyArray.includes as a type guard #31018
I want to use this to improve type guards within code that interacts with untyped third‑party JavaScript. Examples. some-module/index.ts. export ...
Read more >Read-Only Array and Tuple Types in TypeScript - Marius Schulz
That way, your function can be called with mutable and read-only arrays alike. In addition, TypeScript will help you prevent accidental mutation ...
Read more >How do I declare a read-only array tuple in TypeScript?
Since the type [string, number] already is an Array , you can simply use: Readonly<[string, number]>. Example: let tuple: Readonly<[string, ...
Read more >Why you'll love Typescript's ReadonlyArray - ITNEXT
How does Typescript's ReadonlyArray help us in minimizing this sort of errors? Check the image below: As you can see, the compiler warns...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think the only 100% solid approach is for the Babel plugin to add code to any index assignments, length assignments, or function calls on the $ReadOnlyArray identifier
That’s probably true, actually a problem with proxy or copy approach is that neither is === the original array