Skip to content

Export numeric types (Double, Float) as named type aliases, so generated TypeScript closely resembles Kotlin #22

Open
@aSemy

Description

@aSemy

Double and Int are both converted directly to number. This is confusing on the TypeScript side.

@Serializable
data class Position(
  val x: Double,
  val y: Double,
  val level: Int,
)
// generated
export interface Position {
  x: number;
  y: number;
  level: number; // level looks the same as x and y, but if I produce a JSON message with 1.5, KXS will error
}

Unsigned numbers (because they are value classes) are converted to type aliases, e.g.

export interface Score {
  goals: UInt;
}

export type UInt = number;

In TypeScript this isn't safe (UInt can accept any numeric value, despite its name) - but it gives a good indication, and can be enhanced with brand typing (#7).

Can the other numeric primitives be exported as type aliases?

export type Byte = number
export type Short = number
export type Int = number
export type Long = number
export type Float = number
export type Double = number

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions