francescov1 / mongoose-tsgen

A plug-n-play Typescript generator for Mongoose.
102 stars 24 forks source link

Support for schema fields with `-` character? #98

Closed wootwoot1234 closed 2 years ago

wootwoot1234 commented 2 years ago

Thanks for building this great tool, I really appreciate it. I came across an issue when using it on a schema that has a filed with - character.

I have a schema that looks like this:

const MessageRule: MessageRuleSchema = new Schema(
    {
        messages: {
            default: String,
            "zh-TW": String,
            ...
        },
        ....
    }
);

But when I run mtgen src/models -o src/typings/models.ts it errors, see below:

$ mtgen src/models -o src/typings/models.ts
Generating mongoose typescript definitions... done
Writing interfaces to src/typings/models.ts
    SyntaxError: Property or signature expected. (839:1)
      837 | ja?: string;
      838 | zh?: string;
    > 839 | zh-TW?: string;
          | ^
      840 | ko?: string;
      841 | };
      842 | title?: string;
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The terminal process "/bin/bash '-c', 'yarn run mongoose-types'" terminated with exit code: 1.

It seems to be having issues with the - in zh-TW. Is there a work around for this?

francescov1 commented 2 years ago

Hey @wootwoot1234, thanks for flagging this!

We already have an active PR to resolve this: https://github.com/francescov1/mongoose-tsgen/pull/92. Ill try to get this merged in shortly, just waiting on a final fix by the creator.

francescov1 commented 2 years ago

This is resolved in 9.0.8 🎉