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

Thoth.Json.Core generates invalid TypeScript code #202

Open
MangelMaxime opened this issue Jun 20, 2024 · 1 comment
Open

Thoth.Json.Core generates invalid TypeScript code #202

MangelMaxime opened this issue Jun 20, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@MangelMaxime
Copy link
Contributor

MangelMaxime commented Jun 20, 2024

Note

This is reproduction code

type IDecoderHelpers<'JsonValue> =
    abstract isString: 'JsonValue -> bool
    abstract asString: 'JsonValue -> string

type Decoder<'T> =
    abstract member Decode<'JsonValue> :
        helpers: IDecoderHelpers<'JsonValue> * value: 'JsonValue -> obj

let invalidGenerics: Decoder<string> =
        { new Decoder<string> with
            member _.Decode(helpers, value) =
                null
        }

let correctGenerics: Decoder<string> =
        { new Decoder<string> with
            member _.Decode<'JsonValue>(helpers : IDecoderHelpers<'JsonValue>, value) =
                null
        }
import { defaultOf } from "fable-library-js/Util.js";

export interface IDecoderHelpers$1<JsonValue> {
    asString(arg0: JsonValue): string,
    isString(arg0: JsonValue): boolean
}

export interface Decoder$1<T> {
    Decode<JsonValue>(helpers: IDecoderHelpers$1<JsonValue>, value: JsonValue): any
}

export const invalidGenerics: Decoder$1<string> = {
    Decode<JsonValue>(helpers: IDecoderHelpers$1<$a>, value: $a): any {
        return defaultOf();
    },
};

export const correctGenerics: Decoder$1<string> = {
    Decode<JsonValue>(helpers: IDecoderHelpers$1<JsonValue>, value: JsonValue): any {
        return defaultOf();
    },
};

See how the invalidGenerics is using $a instead of JsonValue.

This problem was first reported on Fable repository fable-compiler/Fable#3586 and in private to me.

We should fix this in Fable, but to workaround this issue it is possible to help the compiler infer the correct generics name. In order, to catch all occurence of this issues and make sure Thoth.Json.Core and Thoth.Json.JavaScript can be used on TypeScript, we should also run the tests against TypeScript.

@MangelMaxime MangelMaxime added the bug Something isn't working label Jun 20, 2024
@Freymaurer
Copy link
Contributor

Thanks for looking into this!

MangelMaxime added a commit that referenced this issue Jun 20, 2024
…as the test runner for all targets + Prepare a TypeScript target for officially supporting it

#202
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants