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

Generics with labeled tuple type parameters are parsed incorrectly #434

Open
Programmerino opened this issue Mar 23, 2022 · 1 comment
Open
Labels

Comments

@Programmerino
Copy link

A declaration file containing:

export interface Example {
    problem: Promise<[a: string, b: string]>;
    missed: number;
}

is compiled to (tested on the website and on 0.8.0-build.638)

type [<AllowNullLiteral>] Example =
    abstract problem: Promise<a> with get, set
    abstract string: obj with get, set
    abstract b: string with get, set

My expectation is that, based on how ts2fable normally translates labeled tuple types, it would be compiled to:

type [<AllowNullLiteral>] Example =
    abstract problem: Promise<string * string> with get, set
    abstract missed: float with get, set
@Booksbaum
Copy link
Contributor

Named tuples are a TypeScript 4 feature -- while ts2fable still uses TypeScript 3
-> The old TS parser just cannot handle named tuples and parses names as types ([a: string, b: string] = [a,string,b,string].

Always happens with named tuples:

export declare type A = [a: string, b: number];     
export declare function f(i: [a: string, b: string]): void;

=>

type [<AllowNullLiteral>] IExports =
    abstract f: i: a * string * b * string -> unit

type A =
    a * string * b * float

=> names are parsed as types

As workaround:
Remove names from tuple:

export interface Example {
    problem: Promise<[string, string]>;
    missed: number;
}

=>

type [<AllowNullLiteral>] Example =
    abstract problem: Promise<string * string> with get, set
    abstract missed: float with get, set

Why still TS3?:
The TS Compiler API is quite large, very not-F#_y and there changed a lot with TS4 & newer -> requires A LOT of manual adjustment no-one has done yet.
It's on my TODO list -- but everytime I transform the current TS API with ts2fable I see lots F# compiler errors ... which makes me push the issue further down my TODO list...

So sorry: unfortunately no easy fix, and not anytime soon.
-> Removing names from tuples in d.ts files is currently the way to go :(

@Booksbaum Booksbaum added the bug label Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants