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
// === WORKS =============declarefunctionisPlainObject1(data: unknown,): data is Record<PropertyKey,unknown>;declareconstmyObj1: unknown;if(isPlainObject1(myObj1)){for(constkeyof["a","b","c"]){constdeeper=myObj1[key];// ^?constdeeperKeys=isPlainObject1(deeper) ? Object.keys(deeper) : [];}}// === DOESNT WORK ================// Only difference between the 2 impls is the generic T in the type, even when it isn't used...declarefunctionisPlainObject2<T>(data: unknown,): data is Record<PropertyKey,unknown>;declareconstmyObj2: unknown;if(isPlainObject2(myObj2)){for(constkeyof["a","b","c"]){constdeeper=myObj2[key];// ^?constdeeperKeys=isPlainObject2(deeper) ? Object.keys(deeper) : [];}}
π Actual behavior
The deeper variable, which is nested deeper from the narrowed type is inferred as any.
π Expected behavior
It is the result of accessing a prop on a Record<PropertyKey, unknown> so is expected to be unknown.
Additional information about the issue
I maintain the Remeda utility functions library, I just got this reported here: remeda/remeda#559 and there are additional anecdotal reports that upgrading to typescript 5.4 breaks several of our types.
I couldn't find a reasoning to this issue, including any new changes to Typescript in 5.4 which might explain it.
I'm not sure my title makes sense for this bug, as I don't fully understand what's going on here, or even how to build a truly minimal example.
The text was updated successfully, but these errors were encountered:
Error: 'parents' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.(7022)
π Search Terms
narrow, generic
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?#code/PTAEF5NB1B5AlA0gZQpdH0CgsBMCmAxgDYCGATvqAGYCuAdoQC4CWA9vaCwM4AKZLerABGAKyJMAjAAosoULlJNSALlAMA1vTYB3egBosASjWLlXbqHhE25XAB5e5NgAd85JgE9E+T-vX0Wrr0AHwA3DgEJBRUhBzcTKAAtp4iopJqmtp6ESzUoNI8-KSCaRIyKWmSRkagAN5y8jS2BXH0CaAavqBs+QDaAESkA-4DwiOgA4QDALq1DU1NbR0E+G7kEMmpYpJ9XZ4zEYvyIIsAegD8jYvLiavrPp6W4BbFpWLl0vfutRegZcwAHT7bhffBrH6gNR9Q7XUAAXywiKwp3QoAAIrAAKLIAByABUYAhEGhMGTsKdYPRiJ4FHlqO58IwqMJ8EwdODOEwABZUABMXCSLmIlh4oB5VAA5kz3CxCKBCYJxbzxZ43P58AA3JmgHS8zgsRI8egAckStG4+FwgJtkSIZEoNAYzHYBr4AiEH2YfPs+JCsnkZlUASCekMJgUSlIFisNjsjmc6y8j38WWC4Tt0Udty2aT5mUC2XouXyhXdJU94m90kqYj5NXqcOoLWkOf2PX6QwmY270zmjeOoBz3w2L1roj5e18sMHpyalzh8mH4Ievmerw9AKYfLBEPIv3+XqYwLXu-WtWhM6aiMRQA
π» Code
π Actual behavior
The
deeper
variable, which is nested deeper from the narrowed type is inferred asany
.π Expected behavior
It is the result of accessing a prop on a
Record<PropertyKey, unknown>
so is expected to beunknown
.Additional information about the issue
I maintain the Remeda utility functions library, I just got this reported here: remeda/remeda#559 and there are additional anecdotal reports that upgrading to typescript 5.4 breaks several of our types.
I couldn't find a reasoning to this issue, including any new changes to Typescript in 5.4 which might explain it.
I'm not sure my title makes sense for this bug, as I don't fully understand what's going on here, or even how to build a truly minimal example.
The text was updated successfully, but these errors were encountered: