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

fix(typescript): use declaration merging for factories utilities #14222

Closed
wants to merge 5 commits into from

Conversation

stafyniaksacha
Copy link
Contributor

@stafyniaksacha stafyniaksacha commented Aug 25, 2022

What does it do?

More permissive createCoreController / createCoreService typings

The custom action (service/controller) can be omitted, be an object, or a callback with pre typed ({ strapi }) parameter

const controllers = createCoreController('xxx.xxx.xxx') 
// controllers().transformResponse
// controllers().sanitizeOutput
// controllers().sanitizeInput
// controllers().find
// controllers().delete

findOne/create/update and createOrUpdate are not resolved here:
we can declare which controller uid result in SingleTypeController or CollectionTypeController with declaration merging:

import type { 
  SingleTypeController, 
  CollectionTypeController
} from '@strapi/strapi/lib/core-api/controller';

declare module '@strapi/strapi/lib/types/core/factories' {
  export interface ControllerUidMap {
    'xxx::xxx.uid': SingleTypeController;
    'yyy::yyy.uid': CollectionTypeController;
  }
}

const controllersX = createCoreController('xxx::xxx.uid', ({ strapi }) => {
  bar(ctx) {
    // strapi is typed here, koa ctx is not
  }
}) 
// controllersX().transformResponse
// controllersX().sanitizeOutput
// controllersX().sanitizeInput
// controllersX().find
// controllersX().update
// controllersX().delete
// controllersX().bar

const controllersY = createCoreController('yyy::yyy.uid', { foo() }) 
// controllersY().transformResponse
// controllersY().sanitizeOutput
// controllersY().sanitizeInput
// controllersY().find
// controllersY().findOne
// controllersY().create
// controllersY().update
// controllersY().delete
// controllersY().foo

Related issue(s)/PR(s)

@codecov
Copy link

codecov bot commented Aug 25, 2022

Codecov Report

Base: 57.48% // Head: 57.48% // No change to project coverage 👍

Coverage data is based on head (efc5e42) compared to base (28788e2).
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14222   +/-   ##
=======================================
  Coverage   57.48%   57.48%           
=======================================
  Files        1263     1263           
  Lines       30758    30758           
  Branches     5767     5767           
=======================================
  Hits        17682    17682           
  Misses      11246    11246           
  Partials     1830     1830           
Flag Coverage Δ
front 61.11% <ø> (ø)
unit 49.19% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@innerdvations innerdvations added pr: fix This PR is fixing a bug source: typescript Source is related to TypeScript (typings, tooling, ...) labels Sep 8, 2022
@Convly Convly self-assigned this Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: fix This PR is fixing a bug source: typescript Source is related to TypeScript (typings, tooling, ...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants