Skip to content

Feature request: Typed services, controllers, etc. #17

@Alexnortung

Description

@Alexnortung

Problem

When working with services, you might define your own signatures for functions, which currently is not used or type checked.

For example if I use:

const result = strapi.plugin(pluginId).serice('myService').findOne(1)

I would like findOne to type check that it's parameter should be an id.
I would also like that result would have the type that my function returns.

Possible solution

The idea is that you could provide the plugins/services/controllers as a generic to the IStrapi interface. It would maybe look something like this in practice

import myService from './services/myService'

type MyStrapi = IStrapi<{
  plugins: {
    myPlugin: {
      services: {
        myService: typeof myService
      }
    }
  }
}>

We could also provide more types to populate even more types

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions