You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interfaceApplication{id: string;category: {id: string;}}classApplications{publicFindApplication(query: string): Application|null{returnnull;}}classTest{SelectedApplications: Set<string>=newSet();Applications: Applications|null=null;getSelectedApplicationsByCategory(): Partial<Record<string,Set<string>>>|null{// Workaround 1: move this block inside for loop// Workaround 2: Save this.Applications to a const then use thatif(this.Applications===null){returnnull;}constresult: Partial<Record<string,Set<string>>>={};for(constapplicationIDofthis.SelectedApplications){constapplication=this.Applications.FindApplication(applicationID);if(application===null){continue;}constcategoryID=application.category.id;constapplications=result[categoryID]??newSet<string>();applications.add(application.id);// Comment/uncomment the following line to see it break/unbreakresult[categoryID]=applications;}returnresult;}}
🙁 Actual behavior
application has type: any. FindApplication returns Application | null, but that gets lost somewhere.
🙂 Expected behavior
type for application should be Application | null.
Additional information about the issue
See comments in code for workarounds and to see another line break type inference.
The text was updated successfully, but these errors were encountered:
Gr3q
changed the title
Loss of type for class field in for loop
Loss of type in for-of loop
Apr 22, 2025
🔎 Search Terms
loss of type, for loop, for-loop, class field
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?#code/JYOwLgpgTgZghgYwgAgIIAd0BtgLmYAexGQG8AoZK5YAEwC5kBnMKUAcwG5zLq9J2hKAE9GFahJoNmrDtwkBfckvIIscJkzSYc-IiC3jq6AK4AjXcgBioWhmy58+gBQBHE9FEy2IdgEpGe10nYmQAH2QQEywsMl5JZCgIMBMoEiiY+WolFTUNLQAVCBY4iQBlCCwIBEg7HUcCYiZGCrAAHhYfdgA+ZABeSIgAd2RW5z8sqiCG-WbtBz0m8Mjo2IGMrEnkdmTRyura6cWDACFhAGF8CEERccYABTgoAjgsNoAlaqFaDtlfABo9u1OhxumDlhtSglkAB6GHIADqQgA1k9CCYQLRkABGRgAW0IADcUGAABbALQWQgIZE0Ax0FAwITILCEQjoeKSOGIlFojFYgBMLTgxOQAAMyRSAHRHEIGMXIMCEZBwZAIJpgRWkiAkExMEmk-CciTAGDIZySpgy+rHLR9e0rGJ+KHQ6hJFJpR2bY3ZHiu9UGTVJJjRMAPJ4vN6fdVQH4ggFA35dMG9AakBTcH1UJlQc0BkpwG1ygCSABFkIQzZapRUqjUIHUFnKmM6jK6qPnNYWm40SANq7Le1abJjBy5u8Fe2WJlnJKbzROZqF7etVq3Z-7iAQohAtq6VO2+Bq1VcbsIy-0VUXe1L+NchMIpXQ99DO1ee7NL8HQwBtO9nssAF1kAAfhAwYRlaJNQXGF8EkXW0pTgWhaGcBC5SfWgZ0PKhuXOQg8TxHUwBhDF1UI4itUZQgYkIIYOBZUASWVfUUGATUzCSOBkVIkBOIgbiNzdYpf3-B8gMvdChzg5AD2hd1UhIb8sDALYciAA
💻 Code
🙁 Actual behavior
application
has type:any
.FindApplication
returnsApplication | null
, but that gets lost somewhere.🙂 Expected behavior
type for
application
should beApplication | null
.Additional information about the issue
See comments in code for workarounds and to see another line break type inference.
The text was updated successfully, but these errors were encountered: