fable-compiler / ts2fable

Parser of Typescript declaration files
http://fable.io/ts2fable/
Apache License 2.0
223 stars 34 forks source link

Combined and Omit<> types #474

Open Wouter8 opened 1 year ago

Wouter8 commented 1 year ago

I'm wondering if combined types (using &) and Omitted fields (using Omit<> ) are supported. I understand that these features are not supported by F#, but I was hoping that this tool had a workaround for it.

I tried it in the online demo and it seems ts2fable simply doesn't even try.

Input:

type Foo = {
    field1: "value1" | "value2";
    field2: number;
}

type Combined = Foo & {
    other: string;
}

type Omitted = Omit<Foo, "value">;

Output:

// ts2fable 0.9.0
module rec moduleName
open System
open Fable.Core
open Fable.Core.JS

type [<AllowNullLiteral>] Foo =
    abstract field1: FooField1 with get, set
    abstract field2: float with get, set

type [<AllowNullLiteral>] Combined =
    interface end

type Omitted =
    Omit<Foo, string>

type [<StringEnum>] [<RequireQualifiedAccess>] FooField1 =
    | Value1
    | Value2
Booksbaum commented 1 year ago

I'm wondering if combined types (using &) and Omitted fields (using Omit<> ) are supported.

Unfortunately not supported. Sorry.

In general: I think no Utility Type is currently handled (with exception of NonNullable)

kevinbarabash commented 1 year ago

Many of the utility types are based on mapped types and conditional types which can't really be translated into F#'s type system.