-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
CLI-only error calling generic function #27507
Comments
Here's what's going on with this one: During inference from type The reason it fails with the command-line compiler is that we check The reason we don't get an error in the IDE is that we ask for errors for the current file first so type ids end up following the textual ordering. For the same reason, the error goes away if you specify |
@RyanCavanaugh @DanielRosenwasser We may want to discuss this one in the design meeting. |
Discuss having a stable order for type ids that doesn't depend on check order or altering inference to not just "choose the first type"? Or the issue in general? |
@weswigham Well, I don't see type ids ever having a stable sort order, so really we want to free ourselves from any dependencies on type id ordering. Which for example means we should never depend on the order of types in a union type. |
Whats the 'take the first type' motivation? (Looks like a can of worms to me) |
Rewritten version that is stable between CLI/server type FetchArr<T, K extends keyof T> = T extends { [x in K]: ReadonlyArray<infer E> } ? E : void;
function getFirst<T, K extends keyof T>(obj: T, key: K): FetchArr<T, K> {
return obj[key][0];
}
interface I {
readonly n: ReadonlyArray<number>;
readonly s: ReadonlyArray<string>;
}
function f(i: I): number {
return getFirst(i, "n");
} |
TypeScript Version: 3.2.0-dev.20181002
Code
Expected behavior:
No error.
Actual behavior:
No error in the editor.
Error on the command line:
Related Issues: #19686
The text was updated successfully, but these errors were encountered: