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

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

Open
aSemy opened this issue Apr 9, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@aSemy
Copy link
Contributor

aSemy commented Apr 9, 2022

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
@aSemy aSemy added the enhancement New feature or request label Apr 9, 2022
aSemy added a commit that referenced this issue Apr 11, 2022
…nd update knit to allow for TS Compile to be disabled
aSemy added a commit that referenced this issue Apr 13, 2022
* allow for overriding of elements (partial support for #23 and #22), and update knit to allow for TS Compile to be disabled

* make TsMapTypeConverter more clear, split inline/non-inline

* code tidy

* fix bug where overrides weren't consistently found and applied if the target was nullable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant