simenandre / generate-runtypes

A code generator for Runtypes types. Perfect to create tooling to generate code for Runtypes!
Apache License 2.0
17 stars 2 forks source link

Default name formatter is too brittle #53

Open runeh opened 3 years ago

runeh commented 3 years ago

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 commented 3 years ago

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

haradzienski commented 3 years ago

We actually ended up with a convention like this:

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 commented 3 years ago

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.