prismicio / prismic-ts-codegen

A Prismic model-to-TypeScript-type generator.
Apache License 2.0
18 stars 6 forks source link

fix: support models with IDs starting with a number #30

Closed angeloashmore closed 2 years ago

angeloashmore commented 2 years ago

Types of changes

Description

This PR add support for models with IDs that start with a number.

For example, a Custom Type with an API ID of 404_page or a Shared Slice with an API ID of 2ColumnText is now supported.

Before this PR, the code generator generated invalid code by creating types with names starting with a number. This is invalid TypeScript syntax, similar to starting JavaScript variables with a number.

As of this PR, types starting with a number are prefixed with an underscore (_).

Note: We recommend not starting model IDs with a number.

Using model IDs starting with a number introduces subtle bugs, such as the one described in this issue.

Find alternative ID names if possible. For example, 404Page could be NotFoundPage.

Fixes: #29

Checklist:

🦒

github-actions[bot] commented 2 years ago

size-limit report 📦

Path Size
dist/index.js 1.07 MB (+0.01% 🔺)
dist/index.cjs 1.08 MB (+0.01% 🔺)