Open
Description
trying the new version of metarpheus in gj, we found following issues:
- trait with only one implementation use union type => moved to Handle tagged unions with fewer than two cases metarpheus-io-ts#115
this
@JsonCodec sealed trait AnalyticsReadError
object AnalyticsReadError {
case object BotNotFound extends AnalyticsReadError
}
produces the following non-transipiling code:
export const AnalyticsReadError = t.union([
t.type({
_type: t.literal('BotNotFound')
}, 'BotNotFound')
], 'AnalyticsReadError')
- Record doesn't support NonBlankString as key type => moved to Do not generate
Record
for unsupported key types metarpheus-io-ts#114
final case class RuleConfig(
ruleId: Id[Rule],
params: Map[NonBlankString, NonBlankString],
)
↓
export interface RuleConfig {
ruleId: Id<Rule>,
params: Record<NonBlankString, NonBlankString>
}
- sealed trait with only object implementation produces empty union type
@JsonCodec sealed trait BotDeployStatusError
object BotDeployStatusError {
object BotNotFound extends BotDeployStatusError
}
↓
export const BotDeployStatusError = t.union([
], 'BotDeployStatusError')
- sealed trait that are implemented by an object containing class implementing the same trait because they are a recursive structure, generates two different models, and the second is an unknown
In GJ we have this Tree structure defined as:
sealed trait AnalyzerTree
object AnalyzerTree {
final case class Op(
opType: AnalyzerOpType,
children: NonEmptyList[AnalyzerTree],
) extends AnalyzerTree
final case class Atom(ruleConfig: RuleConfig) extends AnalyzerTree
...<some other methods here>
↓
export type AnalyzerTree =
| {
opType: AnalyzerOpType,
children: NonEmptyList<AnalyzerTree>,
_type: 'Op'
}
| {
ruleConfig: RuleConfig,
_type: 'Atom'
}
export const AnalyzerTree = t.union([
t.type({
opType: AnalyzerOpType,
children: NonEmptyList(AnalyzerTree),
_type: t.literal('Op')
}, 'Op'),
t.type({
ruleConfig: RuleConfig,
_type: t.literal('Atom')
}, 'Atom')
], 'AnalyzerTree')
export type AnalyzerTree = unknown;
export const AnalyzerTree = t.unknown;