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

Typegen result names are not customizable #6562

Open
largis21 opened this issue May 3, 2024 · 1 comment
Open

Typegen result names are not customizable #6562

largis21 opened this issue May 3, 2024 · 1 comment
Labels
typegen Issues related to TypeScript types generation

Comments

@largis21
Copy link
Contributor

largis21 commented May 3, 2024

Is your feature request related to a problem? Please describe.

Most codebases have a strict naming convention, i.e prefixing every type with "i". This is not currently possible with typegen generate.

Describe the solution you'd like

Adding a format property to the sanity-typgen.json config file:

"format": {
  "schemaTypes": {
    "literal": "i{name}Schema",
    "nameCase": "camel" // camel | pascal | snake
  },
  "queries": {
    "literal": "i{name}",
    "nameCase": "camel"
  }
}

Open to suggestions for the api.

Example:

// sanity-typegen.json

{
  "path": "'./**/*.{ts,tsx,js,jsx}'",
  "schema": "schema.json",
  "generates": "sanity.types.ts",
  "format": {
    "schemaTypes": {
      "literal": "i{name}Schema",
      "nameCase": "pascal"
    },
    "queries": {
      "literal": "i{name}",
      "nameCase": "pascal"
    }
  }
}
// Old result

SomeDocumentType = {...}
// New result

iSomeDocumentTypeSchema = {...}

Describe alternatives you've considered

Using as when importing

Additional context
I have submitted a pr which I will extend later today: #6559

@largis21
Copy link
Contributor Author

largis21 commented May 3, 2024

The proof of concept is now finished #6559

@rexxars rexxars added the typegen Issues related to TypeScript types generation label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typegen Issues related to TypeScript types generation
Projects
None yet
Development

No branches or pull requests

2 participants