gzuidhof / tygo

Generate Typescript types from Golang source code
MIT License
551 stars 39 forks source link

Runes are not converted to numbers #56

Open perkrlsn opened 1 month ago

perkrlsn commented 1 month ago

Given the following simple example shouldn't rune be converted to a number?

Input

packages:
  - path: "types/src/test"
    output_path: "src/types.ts"
    type_mappings:
      time.Time: "string /* fancy comment */"
package types

import "time"

type TestType string

type TestRune rune

type TestRunes []rune

type TestStruct struct {
    SomeRune *rune
    SomeTime *time.Time
}

Output

// Code generated by tygo. DO NOT EDIT.

//////////
// source: types.go

export type TestType = string;
export type TestRune = rune;
export type TestRunes = rune[];
export interface TestStruct {
  SomeRune?: rune;
  SomeTime?: string /* fancy comment */;
}
gzuidhof commented 1 month ago

Hmm, I'm not sure what the desired behavior is here, the TS type number is much less restricted than rune.

You could use frontmatter to inject something like export type rune = number and you could get this behavior 🤔, would that solve it for you?

perkrlsn commented 1 month ago

rune isn't a valid TypeScript type. Ideally runes would get converted to number. Unless I'm completely mistaken.