-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Awaited<T> not resolved to T when T is a generic type #47144
Labels
Fix Available
A PR has been opened for this issue
Needs Investigation
This issue needs a team member to investigate its status.
Rescheduled
This issue was previously scheduled to an earlier milestone
Milestone
Comments
RyanCavanaugh
added
the
Needs Investigation
This issue needs a team member to investigate its status.
label
Dec 14, 2021
Got the same problem. Workaround works, thank you) |
I believe I ran into a similar issue in VS Code. On 4.6.0 nightly, this is broken: async function filterDefined<T>(arr: Promise<T | undefined>[]): Promise<T[]> {
const r = await Promise.all(arr);
return r.filter((r): r is T => r !== undefined);
} But adding a type annotation makes it work: async function filterDefined<T>(arr: Promise<T | undefined>[]): Promise<T[]> {
const r: (T | undefined)[] = await Promise.all(arr);
return r.filter((r): r is T => r !== undefined);
} |
I also ran into a similar issue: class Test<Model> {
constructor(private model: Model) {
}
async getObj(): Promise<Partial<Model>> {
return this.model;
}
async getKey<Key extends keyof Model>(obj: Model, key: Key): Promise<Model[keyof Model] | undefined> {
const model = await this.getObj();
// error: Type 'Awaited<Partial<Model>>[Key]' is not assignable to type 'Model[keyof Model] | undefined'.
return model[key];
}
} But when I removed |
Verified that this is still an issue in 4.6.2. |
RyanCavanaugh
added
the
Rescheduled
This issue was previously scheduled to an earlier milestone
label
May 13, 2022
Verified that this is still an issue in 4.8.0-beta |
Thanks @rbuckton! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Fix Available
A PR has been opened for this issue
Needs Investigation
This issue needs a team member to investigate its status.
Rescheduled
This issue was previously scheduled to an earlier milestone
Bug Report
I thought this issue might be related to #46543, but that issue seems to apply to ALL ts versions. This issue is a regression between 4.4.4 and 4.5. In addition to reporting this bug I offer a very simple workaround.
🔎 Search Terms
generic, index, indexed record, type resolution, promise, awaited, workaround
🕗 Version & Regression Information
Bug started in 4.5 release.
Not fixed in the nightly version as of December 14th 7am ET.
⏯ Playground Link
The example below is purposely contrived in order to express the issue in simple terms.
Playground link with relevant code
💻 Code
🙁 Actual behavior
In
brokenExample()
:The type of
const structure
is implicitly resolved toAwaited<GenericStructure<AcceptableKeyType>>
Assignment of
structure[key] = 1;
results in this error:🙂 Expected behavior
In
brokenExample()
:The type of
const structure
should be implicitly resolved toGenericStructure<AcceptableKeyType>
Assignment of
structure[key] = 1;
should not result in an error.The text was updated successfully, but these errors were encountered: