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
If I try to modify a generic nested map-structure and add a property to an object deep in the hierarchy, the generic type cannot follow up and still thinks the object contains the old type. In the following examples, it's all about the type of semiStructuredCols, as I show in the map-functions following the definition.
Example 1:
In this example, I do not assign a specific type, but let the system figure out what I do. It's pretty good, but it seems to keep the parameter cells as in the original object and doesn't use Omit<> to remove it before adding it with the new type. You can see it fail a bit further down in line 29 of the example because of the wrong type.
Example 1 and example 2 fails, but example 3 passes.
Example 1:
Property 'flows' does not exist on type 'FCell'.
Parameter 'f' implicitly has an 'any' type.
Example 2:
Property 'cells' does not exist on type 'FCol | (Omit<ECol, "cells"> & { cells: (ECell | (FCell & { flows: { flowId: string; }[]; }))[]; })'.
Property 'cells' does not exist on type 'FCol'.
Parameter 'c' implicitly has an 'any' type.
Parameter 'f' implicitly has an 'any' type.
🙂 Expected behavior
Both example 1, example 2 and example 3 should pass.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
SimonSimCity
changed the title
Overriding type of union works as declared type but not as
Overriding type of union works as declared type but not as generic type
May 19, 2025
🔎 Search Terms
map, union, generics, property does not exist on type
🕗 Version & Regression Information
Common "Bugs" That Aren't Bugs
andGenerics
.⏯ Playground Link
https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAZiEMC8MA8AoGMCiBhAUwBsiYCAPKAsAEwhgG8YoBPABwIC4YAiYggLbUoPANxkig4QEka3aACcAlmADmMAL4AaLDABihEmUrU6jZuy684REAHcx8W3dnyoytZp3Z8IUhSpaegZdbFYObj5JITARUVCYYGIiCG4ACnxkmAAffUMiAEoAbQBdeOxsNgBDGhoVVW4mSTgobjAAVwEAIwIFcWVVAAtWmA7u3s1yr10DP2NAsxCKiwjrZzEEm3tXGEV6qe0MAD400BT031Jc2cLSgpQjxl1QSFgIQSUAZXd24Ch2hQEGh4Pz0VBnCAAOgEVTYaVOfnuyCOCTOkPCBBQyFQUSksR4CWwAH4nssyTBIZSzt5yRUkiRUok-JD6SlobD4cAkSjaWTgOjLFicVsHDASUxKSytE57IywAQ7DAAIIKBRVFhoJginZ7TwaE73DQwbjAGm8gpmskaQnGplEGkFeK6QH-BRgXYfb4KX6uoEgtkwuEIwoPVHMjFC3j8GIiG3im3LSXUhN05KMtGsqGBzncxICjiR3ExnhixK2hhJ6Ui9OQ6vsuFwB7wAoaC0p63kk1+B3xDTxIA
💻 Code
If I try to modify a generic nested map-structure and add a property to an object deep in the hierarchy, the generic type cannot follow up and still thinks the object contains the old type. In the following examples, it's all about the type of
semiStructuredCols
, as I show in the map-functions following the definition.Example 1:
In this example, I do not assign a specific type, but let the system figure out what I do. It's pretty good, but it seems to keep the parameter
cells
as in the original object and doesn't useOmit<>
to remove it before adding it with the new type. You can see it fail a bit further down in line 29 of the example because of the wrong type.Example 2:
In this example, I try to manually set the type on the variable, which fails miserably - even earlier, but still on line 29 of the example.
Example 3:
I gave up on generic types and tried an explicit type - this seems to work quite well.
🙁 Actual behavior
Example 1 and example 2 fails, but example 3 passes.
Example 1:
Example 2:
🙂 Expected behavior
Both example 1, example 2 and example 3 should pass.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: