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

Default name formatter is too brittle #53

Open
runeh opened this issue Apr 22, 2021 · 3 comments
Open

Default name formatter is too brittle #53

runeh opened this issue Apr 22, 2021 · 3 comments

Comments

@runeh
Copy link
Collaborator

runeh commented Apr 22, 2021

The default name formatter just uppercases the first letter. This doesn't work for types that use a non-alpha prefix. For example, given a value named _links, we now generate this code:

const _links = rt.Record({next: rt.String, prev: rt.String});

type _links = rt.Static<typeof _links>;

We probably don't want the names to be identical, even though it's technically allowed I think.

@simenandre
Copy link
Owner

simenandre commented Apr 22, 2021

I haven't hit this edge-case yet. Thanks for adding the issue!

@haradzienski
Copy link
Contributor

We actually ended up with a convention like this:

  • the runtype name starts with lowercase letter, and has Schema postfix: fooSchema
  • the static type name starts with uppercase letter, and does not have any postfixes: Foo

I think that Schema part came from joi world - it was used for runtime schema validation in pre-runtypes ages on my current project. But the point is still valid, we can just append something like Schema or Runtype or even just Rt to the name to get different names even without uppercasing/lowercasing first letters.

@runeh
Copy link
Collaborator Author

runeh commented Apr 25, 2021

Sounds reasonable. My suggestion, add Runtype to runtypes, and uppercase they types like you say? And explain in docs that the behaviour can be overridden by the naming functions.

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

3 participants