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

added service type as generic type argument #1291

Open
wants to merge 4 commits into
base: next
Choose a base branch
from

Conversation

prasadmadanayake
Copy link

@prasadmadanayake prasadmadanayake commented Jun 12, 2024

Added service type as generic type argument

📝 Description

updated this type definitions for

  • service actions
  • service events
  • lifecycle events
  • service methods
    Now we can properly define custom properties in service interface like
    export interface IMySettings extends ServiceSettingSchema{}

    export interface IMyService extends Service<IMySettings>{
        custom: string
    }

    export class MyService implements Partial<ServiceSchema<IMySettings, IMyService>>{
        name: string = ""
        actions: ServiceActionsSchema<IMySettings, IMyService> = {
            "aa":{
                async handler(cy){
                    console.log(this.custom) // this resolves type correctly
                }

            }

        }
    }

💎 Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

📜 Example code

    export interface IMySettings extends ServiceSettingSchema{}

    export interface IMyService extends Service<IMySettings>{
        custom: string
    }

    export class MyService implements Partial<ServiceSchema<IMySettings, IMyService>>{
        name: string = ""
        actions: ServiceActionsSchema<IMySettings, IMyService> = {
            "aa":{
                async handler(cy){
                    console.log(this.custom)
                }
            }
        }
        methods: ServiceMethods<IMySettings, IMyService> = {
              async a2(){
                  console.log(this.custom)  
              }
        }

        events: EventSchemas<IMySettings, IMyService> = {
            "a3":{
                async handler(cy){
                    console.log(this.custom)
                }
            }
        }

    }

🚦 How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • manually tested with typescript project. no breaking changes with type definition files.

🏁 Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code

@ccampanale
Copy link

I like this idea. We've created and used custom types this way in our system for years but since upgrading to [email protected] we have type errors in all packages. As it exists, refactoring would be huge adjustment (effectively moving all custom service members to module members) but something like this would definitely make this a much smaller effort while being able to once again benefit from our type checking for custom service properties. I'm all for a change like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants