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

Add functions to FormatOptions to modify output interface/type names. #5

Merged
merged 3 commits into from
Jun 10, 2019

Conversation

Reisen
Copy link
Contributor

@Reisen Reisen commented Jun 7, 2019

Aeson provides two functions, fieldLabelModifier and constructorTagModifier which are used to modify the names of fields and data constructor tags, aeson-typescript respects these but gives no control over the ability to modify the names of the interfaces and types it generates.

The main problem this causes happens when you want to generate types for two types from different qualified modules, for example:

import qualified Foo
import qualified Bar
import           Data.Aeson ( defaultOptions )

deriveTypeScript defaultOptions ''Foo.Example
deriveTypeScript defaultOptions ''Bar.Example

Which will create a file with two duplicate types:

// From the first derivation.
type Example = IExample;
interface IExample { ... };

// From the second derivation.
type Example = IExample;
interface IExample { ... }

This PR adds two modifier functions similar to aeson's to FormattingOptions, adding these gives the ability to modify record type names in any way you need. Either automatically with generics or just manually such as:

formatTSDeclaration (FormatOptions 4 (<> "Foo") (<> "Foo")) declaration

To produce:

// From the first derivation.
type ExampleFoo = IExampleFoo;
interface IExampleFoo { ... };

@thomasjm thomasjm mentioned this pull request Jun 10, 2019
@thomasjm
Copy link
Contributor

Thanks! Looks good, merging now.

@thomasjm thomasjm merged commit d00bbd3 into codedownio:master Jun 10, 2019
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

Successfully merging this pull request may close these issues.

None yet

2 participants