Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide support for type augmentation #7940

Closed
dunqan opened this issue Jun 10, 2020 · 3 comments · Fixed by #8534
Closed

Provide support for type augmentation #7940

dunqan opened this issue Jun 10, 2020 · 3 comments · Fixed by #8534
Assignees
Labels
team/blamed Formerly known as Team Aimed and Team Framed; next it will be Team Famed? team/obelix type-augmentation
Milestone

Comments

@dunqan
Copy link
Contributor

dunqan commented Jun 10, 2020

We should allow for the extensibility of our build-in types. Adding more properties for core models helps in implementing a data-driven approach for both our own libraries and 3rd party ones.

There are some well-known limitations in TypeScript around it, mentioned in those tickets:

The "plan of the attack" is:

  1. Expose model we want to allow customers to augment in our public-api.ts
  2. Create an additional build step for our libraries that will move those model also to main entry point generated by ng-packagr (eg spartacus-core.d.ts for core). It could be done by some additional utility script that will run after the build, by creating new builder extending default one or bay using some additional tools (like: https://www.npmjs.com/package/ng-cli-packagr-tasks)
@dunqan dunqan added the team/blamed Formerly known as Team Aimed and Team Framed; next it will be Team Famed? label Jun 10, 2020
@dunqan dunqan added this to the 2.1 milestone Jun 10, 2020
@Xymmer Xymmer modified the milestones: 2.1, 2.1-stretch Jun 27, 2020
@dunqan dunqan self-assigned this Jul 20, 2020
@dunqan dunqan added this to To Do in Spartacus Tribe Board via automation Jul 20, 2020
@dunqan dunqan moved this from To Do to In Progress in Spartacus Tribe Board Jul 20, 2020
@dunqan dunqan moved this from In Progress to To Do in Spartacus Tribe Board Jul 20, 2020
@dunqan dunqan moved this from To Do to In Progress in Spartacus Tribe Board Jul 30, 2020
@dunqan dunqan moved this from In Progress to Code Review & Local QA in Spartacus Tribe Board Aug 11, 2020
@dunqan
Copy link
Contributor Author

dunqan commented Aug 11, 2020

QA steps:

  1. Import and Augment Product model (in app.module for example):
import { Product } from '@spartacus/core';

/...

declare module '@spartacus/core' {
  interface Product {
    custom?: string;
  }
}

2, Confirm that augmenttion works (there is no compilation errors) for both dev and prod builds:

const p: Product = {
  code: '234',
  custom: '43432',
};

console.log(p.code);
console.log(p.custom);

dunqan added a commit that referenced this issue Aug 11, 2020
Allowing for the extensibility of our build-in core models helps in implementing a da- ta-driven approach for both our own libraries and 3rd party ones.

As there are some well-known limitations in TypeScript around it, mentioned in those tickets:

microsoft/TypeScript#9532
microsoft/TypeScript#18877
Spartacus uses additional build step for our libraries that will move augmentable models to main entry point generated by ng-packagr (eg spartacus-core.d.ts for core).

Closes #7940
@dunqan dunqan moved this from Code Review & Local QA to Server/Bug QA in Spartacus Tribe Board Aug 17, 2020
@giancorderoortiz giancorderoortiz self-assigned this Aug 20, 2020
@giancorderoortiz
Copy link
Contributor

Would like to test this one :-)

@Xymmer Xymmer modified the milestones: 2.1-stretch, 2.1 Aug 21, 2020
@giancorderoortiz
Copy link
Contributor

Test successful

@giancorderoortiz giancorderoortiz moved this from Server/Bug QA to Doc Input & Check in Spartacus Tribe Board Aug 24, 2020
@dunqan dunqan moved this from Doc Input & Check to Done in Spartacus Tribe Board Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team/blamed Formerly known as Team Aimed and Team Framed; next it will be Team Famed? team/obelix type-augmentation
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

4 participants