tkrajina / typescriptify-golang-structs

A Golang struct to TypeScript class/interface converter
Apache License 2.0
505 stars 87 forks source link

Tool can't handle packages like ranked-model #53

Closed loeffel-io closed 2 years ago

loeffel-io commented 2 years ago
package main

import (
    "fmt"

    "github.com/ranked-de/ranked-model"
    "github.com/tkrajina/typescriptify-golang-structs/typescriptify"
)

func main() {
    t := typescriptify.New()
    t.CreateInterface = false
    t.BackupDir=""

    t.Add(ranked-model.Test{}) <----

    err := t.ConvertToFile("/Users/lucasloffel/js/ranked/ranked-ui/src/model/test.ts")
    if err != nil {
        panic(err.Error())
    }
    fmt.Println("OK")
}
tkrajina commented 2 years ago

Hm, I can't see a problem in typescriptify here.

Something like this works without problems:

package main

import (
    "fmt"

    testpackage "github.com/tkrajina/typescriptify-golang-structs/test-package"
    "github.com/tkrajina/typescriptify-golang-structs/typescriptify"
)

func main() {
    t := typescriptify.New()
    t.Add(testpackage.Aaaa{})
    err := t.ConvertToFile("test.ts")
    if err != nil {
        panic(err.Error())
    }
}
loeffel-io commented 2 years ago

while generating the main via the cli the testpackage part of testpackage "github.com/tkrajina/typescriptify-golang-structs/test-package" will not be added (the package of the ranked-model directory is model)

tkrajina commented 2 years ago

Ah... I thought this was your code, not the code generated. Maybe a bit more of context (for example how to actually reproduce the error) would have helped initially.

Anyway. Pushed a change in dev. It generates code like this:

package main

import (
        "fmt"

        m "github.com/tkrajina/typescriptify-golang-structs/example/example-models"
        "github.com/tkrajina/typescriptify-golang-structs/typescriptify"
)

func main() {
        t := typescriptify.New()
        t.CreateInterface = true
        t.BackupDir=""

        t.Add(m.Address{})
        t.Add(m.PersonalInfo{})
        t.Add(m.Person{})

        err := t.ConvertToFile("tmp_interfaces.ts")
        if err != nil {
                panic(err.Error())
        }
        fmt.Println("OK")
}

Let me know if it works for you.