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
asyncfunctionmain(): Promise<void>{letvalue=trueawait(async()=>{value=false})()if(value){console.log('value is true')}else{console.log('value is false')}}voidmain()
π Actual behavior
I originally reported this as a bug in typescript-eslint but was told that the underlying type deduction was incorrect in this case and therefore it wasn't a bug there.
The variable value in this code is deduced as type true (seen via hover in vscode on value in the if statement) but would be correctly typed as boolean since it can be (and in this code sample is) changed. If you run the code it logs value is false despite the type being true.
π Search Terms
type inference boolean
π Version & Regression Information
TypeScript 5.4.5
β― Playground Link
https://typescript-eslint.io/play/#ts=5.4.3&fileType=.ts&code=IYZwngdgxgBAZgV2gFwJYHsIwLbFRACgEoAuGABQCd1tUQBTAHgDd1UATAPhgG8AoGDAA29ZDGbAhCejAC8MZJWkCYwAO54xBUJFjE53foMESpM%2BXEkMVAXyLEVqODAKnpRXisFRMIdCIA6IXQAcwIAcjcZOgUlenCiWxh6IQZPYxgfCD9A4LDIyWkYGMtU%2BMTBGz4qvlYOHDxCRKA&eslintrc=N4KABGBECmAeAu0B2ATAzpAXGA2jNANgJZLyYBO0AxgPYC2dyK0KkANFAA4ECuA5iUwABeAE9O0NFXJFO8ALSTipAPRp4MqgrET5VABbUA1i0gBdEAF8QQA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
π» Code
π Actual behavior
I originally reported this as a bug in typescript-eslint but was told that the underlying type deduction was incorrect in this case and therefore it wasn't a bug there.
The variable
value
in this code is deduced as typetrue
(seen via hover in vscode onvalue
in the if statement) but would be correctly typed asboolean
since it can be (and in this code sample is) changed. If you run the code it logsvalue is false
despite the type beingtrue
.I have a slightly simpler playground that does not involve an async function here: https://www.typescriptlang.org/play/?ts=5.4.5#code/DYUwLgBAbghsCuIIF4IDM4GcQG4BQA2gORoD2pRAugHRkBOAojAMYAWAFO2CAB5gCUKAHwQA3ngjQ4iFBDB1E+AL798ASzQR2sBCEHjJzUgDtMpUNWCkA5uyI6ZazHIUgiqvEoghg2MRIgjU3MQSxs7ByQndCw3DyUgA
π Expected behavior
value
should have the typeboolean
Additional information about the issue
xref typescript-eslint/typescript-eslint#9055
The text was updated successfully, but these errors were encountered: