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

schmervice and typescript #17

Open
ianjkaplan opened this issue Sep 4, 2021 · 7 comments
Open

schmervice and typescript #17

ianjkaplan opened this issue Sep 4, 2021 · 7 comments

Comments

@ianjkaplan
Copy link

Hello Im having a little trouble using Schmervice with typescript. I have imported @types for schmervice and I delare a class on a src/lib/services diresctory. i keep getting the error 'service must have a name' message meaning im not extending the base class properly. any initial guidance on setting up schmervice with typescript would be appreciated

@devinivy
Copy link
Member

devinivy commented Sep 4, 2021

It's a little hard to guess what the issue might be: can you share the code for your service that is causing this error? Also, this sounds like a runtime error from schmervice rather that an error from typescript— is that correct?

@ianjkaplan
Copy link
Author

import { Service } from '@hapipal/schmervice';

export class MeService extends Service {

    constructor(server, options) {

        super(server, options);

    }
}

im using hautecouture as well. I think it might be a ts config thing since the error resolves as long as the generated js file exports a class with module.exports

@ianjkaplan
Copy link
Author

Also, this sounds like a runtime error from schmervice rather that an error from typescript— is that correct?
yes this is a runtime error

@devinivy
Copy link
Member

devinivy commented Sep 4, 2021

I think the issue here is that the class is a named export. In CJS your example would look roughly like this:

exports.MeService = class MeService extends Service {};

Instead we want it to be the entire export for haute-couture, like this:

module.exports = class MeService extends Service {};

In typescript I believe that means you want a default export. Does this work for you?

import { Service } from '@hapipal/schmervice';

// Note the default keyword below
export default class MeService extends Service {

    constructor(server, options) {

        super(server, options);

    }
}

@ianjkaplan
Copy link
Author

ianjkaplan commented Sep 4, 2021

ok i had a default export in my code. I actually resolved the error if i assign MeService to module.exports in the .ts files otherwise it complies to exports.default = MeService which throws the runtime error.

@devinivy
Copy link
Member

devinivy commented Sep 4, 2021

Curious! The export default really is supposed to work correctly for files with a .ts extension— there is some logic for this in haute-couture (it is aware of typescript's use of the exports.default property). If you confirm that my example above with the default keyword does not work then I will take a deeper look at it. In any case, glad you were able to get this to work for you!

@ianjkaplan
Copy link
Author

Thanks. I will confirm that default export does produce the error while setting module.exports does not. If you look into it I'd be curious to learn what you find!

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

No branches or pull requests

2 participants