-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Higher order type parameter promotion fixes #30363
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
Conversation
@typescript-bot run dt let's see if this fixes ramda completely~ |
Heya @weswigham, I've started to run the Definitely Typed test suite on this PR at e7afa6c. You can monitor the build here. It should now contribute to this PR's status checks. |
@ahejlsberg this looks new: Error in css-tree
Error: /home/vsts/work/1/s/dtslint-runner/DefinitelyTyped/types/css-tree/css-tree-tests.ts:211:1
ERROR: 211:1 expect Expected type to be:
List<Test>
got:
List<Test | null>
ERROR: 219:1 expect Expected type to be:
List<Test>
got:
List<Test | null> might be unrelated, though, don't know. The other failures are caused by #30334 and fixed by #30375. |
Here's the testcase from // @strict: true
interface ListItem<TData> {
prev: ListItem<TData> | null;
next: ListItem<TData> | null;
data: TData;
}
type IteratorFn<TData, TResult, TContext = List<TData>> = (this: TContext, item: TData, node: ListItem<TData>, list: List<TData>) => TResult;
type FilterFn<TData, TResult extends TData, TContext = List<TData>> = (this: TContext, item: TData, node: ListItem<TData>, list: List<TData>) => item is TResult;
declare class List<TData> {
filter<TContext, TResult extends TData>(fn: FilterFn<TData, TResult, TContext>, context: TContext): List<TResult>;
filter<TResult extends TData>(fn: FilterFn<TData, TResult>): List<TResult>;
filter<TContext>(fn: IteratorFn<TData, boolean, TContext>, context: TContext): List<TData>;
filter(fn: IteratorFn<TData, boolean>): List<TData>;
}
interface Test {
a: string;
}
const list2 = new List<Test | null>();
const filter1 = list2.filter(function(item, node, list): item is Test {
this.b; // $ExpectType string
item; // $ExpectType Test | null
node; // $ExpectType ListItem<Test | null>
list; // $ExpectType List<Test | null>
return !!item;
}, {b: 'c'});
filter1; // $ExpectType List<Test> the change in expected type of |
Noooooope, I think it's due to the subtle change in inference for return type predicates. |
Specifically, we check for a matching parameter index.... except we don't account for |
I opened a PR against this PR - #30386 - with a fix. |
Latest commit changes |
Wanna add the test from #30386 so we have more coverage? |
@weswigham Sure, I can do that. |
@typescript-bot run dt |
Heya @ahejlsberg, I've started to run the Definitely Typed test suite on this PR at 3dd0814. You can monitor the build here. It should now contribute to this PR's status checks. |
The DT run looks great - just has the instantiation error that was in |
This PR makes a couple of tweaks to our higher order type parameter promotion algorithm. Specifically, we don't promote type parameters of a function type argument when the contextual signature doesn't reference type parameters in parameter positions, and we now treat inferences made from parameter positions in type parameter promotion as contravariant.
Fixes #30324.