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
Currently we expose only some models (e.g. Product) to be augmentable (extendable) for customers.
Goal
For the great extensibility experience for customers, ideally we should expose all TS models as augmentable. We don't do it currently, because, according to the current approach, it requires a hassle declaring manually all those models in public_api.ts. (which is cumbersome and prone to leftovers).
The reason extendable models must be declared flatly in public_api.ts
Current limitation of Typescript: the models re-exported in public_api.ts via barrels index.ts files (export * from ./local/file) cannot be augmented. See TS issues:
Details of our current solution (which is used only for some models)
To workaround it, in Spartacus we export manuallyONLY SOME most-frequently-extended types in the public_api.ts, and then thanks to our custom builder, we copy-paste those types definitions into the main output .d.ts file in /dist folder of a library.
Let's automate flattening d.ts files
We should research how we can automate flattening d.ts files, so all models are declared in the build output public_api.d.ts
The Angular team has built their own custom naive mechanism for flattening their d.ts files when packaging their libraries, however the mechanism has some limitations (as this comment says). Maybe we could reuse this logic, if only we understand and accept the limitations.
The text was updated successfully, but these errors were encountered:
Current state
Currently we expose only some models (e.g.
Product
) to be augmentable (extendable) for customers.Goal
For the great extensibility experience for customers, ideally we should expose all TS models as augmentable. We don't do it currently, because, according to the current approach, it requires a hassle declaring manually all those models in
public_api.ts
. (which is cumbersome and prone to leftovers).The reason extendable models must be declared flatly in
public_api.ts
Current limitation of Typescript: the models re-exported in
public_api.ts
via barrelsindex.ts
files (export* from ./local/file
) cannot be augmented. See TS issues:export *
microsoft/TypeScript#9532Details of our current solution (which is used only for some models)
To workaround it, in Spartacus we export manually ONLY SOME most-frequently-extended types in the public_api.ts, and then thanks to our custom builder, we copy-paste those types definitions into the main output
.d.ts
file in/dist
folder of a library.Let's automate flattening d.ts files
We should research how we can automate flattening d.ts files, so all models are declared in the build output
public_api.d.ts
Results of preliminary research:
ng-packagr
would allow for flattening d.ts out of the box, see issue Flatten type definitions to a single *.d.ts file ng-packagr/ng-packagr#139rollup
(not sure if we can use it)The text was updated successfully, but these errors were encountered: