Skip to content

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

Merged
thomasjm merged 3 commits intocodedownio:masterfrom
Reisen:master
Jun 10, 2019
Merged

Add functions to FormatOptions to modify output interface/type names.#5
thomasjm merged 3 commits intocodedownio:masterfrom
Reisen:master

Conversation

@Reisen
Copy link
Copy Markdown
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
Copy Markdown
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.

2 participants