-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
Surprising circularity error in 3.9 RC #38279
Comments
I introduced |
@RyanCavanaugh We didn't catch this in our last pass because it was downstream from a boring break. |
This looks to be a case of an object literal being contextually typed by itself. I'm pretty sure the reason we didn't report it previously is that during mapped type member resolution we'd temporarily set the result to an empty array, eagerly compute all the member types, and then overwrite that empty array with the final result. We now properly defer resolution of mapped type member types which enables us to catch circularities and report them. And that's what's happening here. |
The quick fix here is to add a |
Or any explicit type - probably |
@ktsn @HerringtonDarkholme @Kingwl @jackkoppa @blake-newman have any of you been able to give TypeScript 3.9 a try with Vue? |
I think "object ends up contextually typing itself" is actually a pretty common scenario in vue. 😦 I know I've debugged many an issue in the past with that exact premise, and I've usually made the fix something along the lines of adjusting contextual typing or inference so the object no longer depended upon itself. |
It seems to be an issue about mapping type and function overload. I can reproduce the issue in a minimal fashion: type Func<T> = () => T
type Mapped<T> = {
[K in keyof T]: Func<T[K]> // error
// [K in keyof T]: () => T[K] // this compiles
}
declare function reproduce(options: number): void // removing this line also compiles
declare function reproduce<T>(options: Mapped<T>): T
reproduce({
name: () => { return 123 } // ERROR
})
reproduce({
name() { return 123 } // ok
})
reproduce({
name: function () { return 123 } // ok
}) Curiously, without the type alias Even weirder, changing arrow function to method or plain function also makes it compile. Playground link for nightly build |
Well, this error can be a same one? I've found similar error message when using recursive generic type. The error only occured in the v3.9.2 version. No error in the old v3.8.3 version. |
Thanks for checking, @DanielRosenwasser - just tried out All in all, it wouldn't be a huge deal-breaker for TS + Vue devs, to have to add return type annotations to those methods, though a bit of a pain. I primarily worry for people who run into the problem as they upgrade, given that Vue 2 is inherently a bit fragile in its type definitions (with all the circularity involved); since the error message is about the way |
Repro case: https://github.com/jackkoppa/ts-38279-repro |
Since this is a regression I'm going to label it a bug. As I said above, the issue here is an object literal that is contextually typed by itself. I think we can fix it by not producing a contextual type in cases where resolution of a contextual mapped type property would cause a circularity error. |
Please reopen, the issue still persists on TypeScript 3.9.3. See @jackkoppa repo and bump the TypeScript version to 3.9.3. Circular references are still there so TypeScript 3.9 can't be currently used on Vue projects. |
We'll include this in our May Servicing release |
Is this included in 3.9.5? how to reproduce:
|
The change never got accepted into the 3.9 branch: #38687 |
Yup, can confirm that we still see the same issue in |
@RyanCavanaugh is this going to get ported/accepted into a 3.9 release at some point? Because right now the milestone is at least misleading, since it didn't go out in the last one. |
Did this go into |
I haven't had a chance to reduce the repro, but people seem eager to get started. I'll try to update with better steps. For now:
packages/core/src/actions.ts:108:9 - error TS2783: 'type' is specified more than once, so this usage will be overwritten.
Expected: no errors, as in 3.8.3
Actual:
TypeScript Version: 3.9.1-rc
The text was updated successfully, but these errors were encountered: