-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Array of generic functions not assignable to ReadonlyArray #20454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
A possibly related problem: declare function flatten<T>(array: ReadonlyArray<ReadonlyArray<T>>): T[];
declare const x: number[][];
const y = flatten(x); // Got `{}[]`, wanted `number[]`. Works with an explicit type argument |
Possibly related issue: generic type is not inferred correctly for function at<T>(object: T, key: ReadonlyArray<keyof T>): Array<T[keyof T]> {
// Do stuff...
}
let result: number[];
result = at({ a: 1, b: 2 }, ["a"]); // Error: Argument of type '{ a: number; b: number; }' is not assignable to parameter of type '{ a: any; }'.
result = at({ a: 1, b: 2 }, ["a", "b"]); // Error: Argument of type '{ a: number; b: number; }' is not assignable to parameter of type '{ a: any; }'.
const obj = { a: 1, b: 2 };
result = at(obj, ["a", "b"]); // Error: Argument of type '("a" | "b")[]' is not assignable to parameter of type 'ReadonlyArray<"a">'.
result = at<{ a: number, b: number }>({ a: 1, b: 2 }, ["a", "b"]); // Works Changing |
comparing array to ReadonlyArray structurally with |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.7.0-dev.20171203
Code
Expected behavior:
No error.
Actual behavior:
The text was updated successfully, but these errors were encountered: