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
///** * The mapping interface that we use to implement interfaces multiple times */exportdeclaretypeImplementExplicit<T,TPropertySuffixextendsstring>={[PropertyinkeyofTas `${PropertyextendsString ? Property : never}_${TPropertySuffix}`]: T[Property];};/** * The resulting interface that we use elsewhere in the code */exportinterfaceI<TSuffixextendsstring>extendsMAPD_I<TSuffix>{}/** * The type definition that maps the interface "prototype" or template * and adds a suffix */exporttypeMAPD_I<TSuffixextendsstring>=ImplementExplicit<TMPL_I, `umP47l$_${TSuffix}_$`>;/** * The "prototype" or template of the interface */exportinterfaceTMPL_I{Property: string;}
🙁 Actual behavior
Throws the following error: semantic error TS2312: An interface can only extend an object type or intersection of object types with statically known members
🙂 Expected behavior
No error just like in previous versions
Remarks
We are using this type of interface pattern to achieve explicit implementations (Like in other languages e.g. c#). I'm aware that this a bit of a hack to get something like this to work in typescript. We do it to be able to replicate data classes that we have written in other languages. The goal is to implement the same interface multiple times. It is useful when the same interfaces is implemented with different generic arguments and thus needs to have the implemented properties multiple times with different types.
E.g. to achieve something like this:
interfaceSomeInterface<T>{property: T}classDataClassextendsSomeInterface<string>,SomeInterface<number>{// Impossible to implement as "property" would now collide: i.e. we can't have one version with "string" and one with "number"}
This is not shown here to have a minimal example that is as simple as possible. The behaviour could be achieved in typescript 3.8.4 by providing a suffix (TSuffix) when implementing an interface (As shown in the example). This suffix gets added to all properties, such that they can exist multiple times on the same object
I'm aware that what we are doing might not be intended to work in the typescript standard, but its in my opinion not acceptable if such behavior changes in a minor version update. In our case npm automatically upgraded the typescript version and all our build scripts suddenly broke.
The text was updated successfully, but these errors were encountered:
sidney-pauly
changed the title
Undetected breaking change in 4.9: "semantic error TS2312" appears for some interface setups
Regression in 4.9: "semantic error TS2312" appears for some interface setups
Nov 16, 2022
I'm aware that this a bit of a hack to get something like this to work in typescript.
Indeed, it was a bug that this was ever not flagged as an error. See PR #51050.
Any upgrade, including a patch release, is liable to break code that (even unintentionally) relies on a bug in order to function.
Hello @RyanCavanaugh would it be possible to make this optionally somehow possible using a unsafe keyword? We are using generated typescript and have use cases where we want that behavior.
I understand your point of thinking and making typescript more typesafe and robust, but I feel disapointed cause in our case it makes perfect sence to do that and the recent update makes us stuck on typescript 4.8 with a large code base.
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
⏯ Playground Link
Playground link
💻 Code
🙁 Actual behavior
Throws the following error:
semantic error TS2312: An interface can only extend an object type or intersection of object types with statically known members
🙂 Expected behavior
No error just like in previous versions
Remarks
We are using this type of interface pattern to achieve explicit implementations (Like in other languages e.g. c#). I'm aware that this a bit of a hack to get something like this to work in typescript. We do it to be able to replicate data classes that we have written in other languages. The goal is to implement the same interface multiple times. It is useful when the same interfaces is implemented with different generic arguments and thus needs to have the implemented properties multiple times with different types.
E.g. to achieve something like this:
This is not shown here to have a minimal example that is as simple as possible. The behaviour could be achieved in typescript 3.8.4 by providing a suffix (
TSuffix
) when implementing an interface (As shown in the example). This suffix gets added to all properties, such that they can exist multiple times on the same objectI'm aware that what we are doing might not be intended to work in the typescript standard, but its in my opinion not acceptable if such behavior changes in a minor version update. In our case npm automatically upgraded the typescript version and all our build scripts suddenly broke.
The text was updated successfully, but these errors were encountered: