Skip to content

Latest commit

Β 

History

History
1051 lines (799 loc) Β· 30.8 KB

CHANGELOG.md

File metadata and controls

1051 lines (799 loc) Β· 30.8 KB

Changelog

All notable changes to this project will be documented in this file.

This project adheres to Semantic Versioning.

0.12.0

πŸš€ Features

  • Add basic support for Readonly<T> (20dab77)

    export interface TerminalOptions {
        prefix: string
    }
    
    export type ReadonlyTerminalOptions = Readonly<TerminalOptions>
    [<AllowNullLiteral>]
    [<Interface>]
    type TerminalOptions =
        abstract member prefix: string with get, set
    
    [<AllowNullLiteral>]
    [<Interface>]
    type ReadonlyTerminalOptions =
        abstract member prefix: string with get
  • Make Partial<T> support more robust (b7e9030)

    • Support literal types:

      export type TodoPreview = Partial<{
          title: string;
          description: string;
      }>;
      [<AllowNullLiteral>]
      [<Interface>]
      type TodoPreview =
          abstract member title: string option with get, set
          abstract member description: string option with get, set
    • Support intersection

      interface Todo {
          title: string;
      }
      
      interface TodoExtra {
          author: string;
      }
      
      export type TodoPreview = Partial<Todo & TodoExtra>;
      [<AllowNullLiteral>]
      [<Interface>]
      type Todo =
          abstract member title: string with get, set
      
      [<AllowNullLiteral>]
      [<Interface>]
      type TodoExtra =
          abstract member author: string with get, set
      
      [<AllowNullLiteral>]
      [<Interface>]
      type TodoPreview =
          abstract member title: string option with get, set
          abstract member author: string option with get, set
  • Add support for Iterable type (12ad780)

    Iterable can be detect if a type implements Iterable<...> or if a TypeLiteral has a [Symbol.iterator]() method signature.

    For [Symbol.iterator](), we also support auto detection of the type looking at the next.value signature type.

    export declare class DataTransfer implements Iterable<string> {
        [Symbol.iterator](): IterableIterator<string>
    }
    
    export type MyIterable = {
        [Symbol.iterator](): {
            next(): {
                done: boolean;
                value: number;
            };
            return(): {
                done: boolean;
            };
        };
    };
    <AllowNullLiteral>]
    [<Interface>]
    type DataTransfer =
        inherit Iterable<string>
    
    [<AllowNullLiteral>]
    [<Interface>]
    type MyIterable =
        inherit Iterable<float>
  • Add support for Omit<Type, Keys> (3e00942)

    export interface Todo {
        title: string;
        description: string;
        completed: boolean;
        createdAt: number;
    }
    
    export type TodoPreview = Omit<Todo, "description">;
    [<AllowNullLiteral>]
    [<Interface>]
    type Todo =
        abstract member title: string with get, set
        abstract member description: string with get, set
        abstract member completed: bool with get, set
        abstract member createdAt: float with get, set
    
    [<AllowNullLiteral>]
    [<Interface>]
    type TodoPreview =
        abstract member title: string with get, set
        abstract member completed: bool with get, set
        abstract member createdAt: float with get, set

🐞 Bug Fixes

  • Support single case out of Exclude<UnionType, ExcludedMembers> (7b8a7c0)

    export type NumberB = Exclude<1 | 2, 2>;
    
    export type PrimitiveResult = Exclude<"a" | "b", "a">;
    [<RequireQualifiedAccess>]
    type NumberB =
        | ``1`` = 1
    
    [<RequireQualifiedAccess>]
    [<StringEnum(CaseRules.None)>]
    type PrimitiveResult =
        | b
  • Type constraint should not be generated when the type is a "return type" (73d6cd7)

    class A {}
    
    class User<T extends A = A> {}
    [<AbstractClass>]
    [<Erase>]
    type Exports =
        [<Import("User", "REPLACE_ME_WITH_MODULE_NAME"); EmitConstructor>]
        static member User<'T when 'T :> A> () : User<'T> = nativeOnly
    
    [<AllowNullLiteral>]
    [<Interface>]
    type A =
        interface end
    
    [<AllowNullLiteral>]
    [<Interface>]
    type User<'T when 'T :> A> =
        interface end

0.11.0

πŸš€ Features

  • Add support for ThisParameterType (dba7588)

    declare function toHex(this: number): string;
    declare function numberToString(n: ThisParameterType<typeof toHex>): string;
    [<AbstractClass>]
    [<Erase>]
    type Exports =
        [<Import("toHex", "REPLACE_ME_WITH_MODULE_NAME")>]
        static member toHex (this: float) : string = nativeOnly
        [<Import("numberToString", "REPLACE_ME_WITH_MODULE_NAME")>]
        static member numberToString (n: float) : string = nativeOnly
  • Alias Error to Exception (a5078c8)

    export type T = Error
    type T =
        Exception
  • Use ReadonlyArray from Glutinum.Types (205b596)

    export type T = ReadonlyArray<number>
    // You need to add Glutinum.Types NuGet package to your project
    open Glutinum.Types
    
    type T =
        ReadonlyArray<float>
  • Add support for ReturnType (6075659)

    export type T1 = ReturnType<any>;
    export type T2 = ReturnType<(s: string) => void>;
    export type T3 = ReturnType<<T extends U, U extends number[]>() => T>;
    type T1 =
        obj
    
    type T2 =
        unit
    
    type T3 =
        ResizeArray<float>
  • Transform FunctionType to delegate if there are 2 or more parameters (b7150a7)

    export interface MyObject<A,B, NotNeeded> {
        upper: (s : string) => string;
        random: (min: number, max: number) => number;
        foo: (min: A, max: B) => B;
    }
    [<AllowNullLiteral>]
    [<Interface>]
    type MyObject<'A, 'B, 'NotNeeded> =
        abstract member upper: (string -> string) with get, set
        abstract member random: MyObject.random with get, set
        abstract member foo: MyObject.foo<'A, 'B> with get, set
    
    module MyObject =
    
        type random =
            delegate of min: float * max: float -> float
    
        type foo<'A, 'B> =
            delegate of min: 'A * max: 'B -> 'B
  • Add support for ReadonlyArray and it's equivalent readonly T[] (a24335b)

    export type Standard = ReadonlyArray<number>
    
    export type Alias = readonly number[];
    type ReadonlyArray<'T> = JS.ReadonlyArray<'T>
    
    type Standard =
        ReadonlyArray<float>
    
    type Alias =
        ReadonlyArray<float>
  • Support piping CLI output to a file (14ba216)

  • Add replacement for Function to System.Action (23ef41f)

    interface sharedEvents {
        getEventState: Function
    }
    [<AllowNullLiteral>]
    [<Interface>]
    type sharedEvents =
        abstract member getEventState: Action with get, set
  • Remove warning when seeing ConstructorType + keep in the output TypeAlias that we don't know how to handle (60a0f83)

  • Improve reader error message to include the caller file + use the name of the SyntaxKind instead of its numeric value (54913da)

🐞 Bug Fixes

  • Make Reader error reporter support node without a source file attached to them (190ea17)

  • IndexSignature decorated with readonly should not generate a setter (5cb91ef)

    export interface MyType {
        readonly [n: number]: string;
    }
    [<AllowNullLiteral>]
    [<Interface>]
    type MyType =
        [<EmitIndexer>]
        abstract member Item: n: float -> string with get
  • Improve support for ConstructorType (d4512a9)

    type Simple = new(config?: string) => number;
    
    type WitGeneric<T> = new(config?: string) => T;
    type Simple =
        obj
    
    [<Erase>]
    type WitGeneric<'T> =
        | WitGeneric of 'T
    
        member inline this.Value =
            let (WitGeneric output) = this
            output
  • Allows interface to be printed as type with generics (f63db34)

  • Open statement from open Glutinum.Types to open Glutinum.Types.TypeScript (7325d86)

  • Sanitise the scopeName when generating additional types (0f5228b)

    Note how params is escaped

    export interface Test {
        callback: ((params: {
            table: string;
        }) => void)
    }
    [<AllowNullLiteral>]
    [<Interface>]
    type Test =
        abstract member callback: (Test.callback.``params`` -> unit) with get, set
    
    module Test =
    
        module callback =
    
            [<Global>]
            [<AllowNullLiteral>]
            type ``params``
                [<ParamObject; Emit("$0")>]
                (
                    table: string
                ) =
    
                member val table : string = nativeOnly with get, set
  • Don’t add a space if XmlDocLine is empty (f1be351)

  • Supports generics for ThisType (886d8a5)

    export interface MyObject<T> {
        instance: () => this;
    }
    [<AllowNullLiteral>]
    [<Interface>]
    type MyObject<'T> =
        abstract member instance: (unit -> MyObject<'T>) with get, set
  • Add option when printing F# Function if the parameter is marked as optional (8be3190)

    interface AlertStatic {
      alert: (
        title: string,
        message?: string
      ) => void;
    }
    [<AllowNullLiteral>]
    [<Interface>]
    type AlertStatic =
        abstract member alert: (string -> string option -> unit) with get, set
  • Use @ts-morph/bootstrap to setup TypeScript for CLI usage (8521fc6)

  • Remove debug log (9567a12)

  • Don't emit warning when seeing an EmptyStatement (85bb658)

    Empty statement happens when a ; is used in a place where it is not needed

    ;

    or

    interface sharedEvents {
        getEventState: Function
    };
  • Prevent error reporter to crash if the parent node is undefined (bf0cb8f)

  • Add support for combination keyof typeof (a0babc8)

    export enum ColorsEnum {
        white = '#ffffff',
        black = '#000000',
    }
    
    export type Colors = keyof typeof ColorsEnum;
    [<RequireQualifiedAccess>]
    [<StringEnum(CaseRules.None)>]
    type ColorsEnum =
        | [<CompiledName("#ffffff")>] white
        | [<CompiledName("#000000")>] black
    
    [<RequireQualifiedAccess>]
    [<StringEnum(CaseRules.None)>]
    type Colors =
        | white
        | black
  • Support for union using Array interface (1a35d4c)

    export type NumberOrNumberArray = number | Array<number>
    type NumberOrNumberArray =
        U2<float, ResizeArray<float>>
  • Add support for literal enums with @, <, >, (space) (883829c)

  • Support resolving name when deconstructing a parameter (04a82dc)

    export interface LogOptions {
        prefix: string;
    }
    
    export interface Context {
        indentationLevel: number;
    }
    
    declare class Signature {
        toText({ indentationLevel }: Context, data : string, {prefix }?: LogOptions): string;
    }
    [<AllowNullLiteral>]
    [<Interface>]
    type LogOptions =
        abstract member prefix: string with get, set
    
    [<AllowNullLiteral>]
    [<Interface>]
    type Context =
        abstract member indentationLevel: float with get, set
    
    [<AllowNullLiteral>]
    [<Interface>]
    type Signature =
        abstract member toText: arg0: Context * data: string * ?arg2: LogOptions -> string

0.10.0

πŸš€ Features

  • Merge duplicated types and module (acf4571)

    Interfaces exemple:

    export interface PointGroupOptions {
        size: number;
    }
    
    export interface PointGroupOptions {
        label: string;
    }
    [<AllowNullLiteral>]
    [<Interface>]
    type PointGroupOptions =
        abstract member size: float with get, set
        abstract member label: string with get, set

    Modules example:

    export module Log {
    
        export interface Options {
            prefix: string
        }
    
        export interface Options {
            suffix: string
        }
    }
    
    export module Log {
    
        export function log() : void;
    
        export interface Options {
            level: number
        }
    }
    module Log =
    
        [<AllowNullLiteral>]
        [<Interface>]
        type Options =
            abstract member prefix: string with get, set
            abstract member suffix: string with get, set
            abstract member level: float with get, set
    
        [<AbstractClass>]
        [<Erase>]
        type Exports =
            [<Emit("$0.log($1...)")>]
            abstract member log: unit -> unit
  • Add Partial<T> supports + add typeMemory access for later reference (38eb08e)

    export interface PointGroupOptions {
        dotSize: number;
    }
    
    export interface Options extends Partial<PointGroupOptions> {
        minDistance?: number;
    }
    [<AllowNullLiteral>]
    [<Interface>]
    type PointGroupOptions =
        abstract member dotSize: float with get, set
    
    [<AllowNullLiteral>]
    [<Interface>]
    type Options =
        abstract member minDistance: float option with get, set
        abstract member dotSize: float option with get, set

🐞 Bug Fixes

  • Generate constructor when a class is exported as default (8e60ee7)
  • Do not include this argument when generating signature of a FunctionType (dd86e28)

0.9.0

πŸš€ Features

  • Improve detection of StandardLibrary types like Promise, Boolean and add supports for RegExp via a type alias (bd97580)
  • Add support for TemplateLiteralType (e75209f)
  • Add supports for TypeAliasDeclaration when used as a returned type (cd58d28)
  • Add supports for Record<A,B> when used as a returned type (b705f37)
  • Add supports for IntersectionType when used as a type signature (9d12fce)
  • During transformation phase accumulate errors and warnings in memory, so they can be reported in the web tool (7548317)
  • Add support for LiteralType (aka literal values used as types) (2cce022)
  • Add support for Record<A,B> (1a94129)
  • Add support for ConditionalType (6279137)
  • Add supports for generics constraints (b1dff0e)

🐞 Bug Fixes

  • Improve TypeReference supports when inside of an Union especially when dealing with TypeParameters (cc99bab)
  • If an argument is decorated with ? and undefined or null remove the option type (a413d14)
  • Use REPLACE_ME_WITH_MODULE_NAME everywhere instead of module (1c78943)
  • Supports TypeQuery against FunctionType (8fd0e35)
  • Don't generate constraints for Function as this is not supported by F# (e3a573d)
  • Sanitize ModuleDeclaration name + generates only 1 exports property per ModuleDeclaration (8d40f9f)

0.8.0

πŸš€ Features

  • Add supports for split get/set declaration field (fa6128f)
  • Add support for HeritageClauses on classes (70c6e11)
  • Add support for HeritageClauses on interfaces (046bccd)
  • Improve Exports generation to use abstract when the exports is not at the top level (6fb991c)
  • Support transforming Partial<T> types (9b01819)

🐞 Bug Fixes

  • Don't crash when handling a type which resolves to Partial<unknown> (0b91986)

0.7.0 - 2024-07-01

πŸš€ Features

  • Generate an interface instead of an erased union when handling an union of type literal
  • Add support for @throws in TSDoc
  • Add TSDoc support for TypeAlias
  • Add support for TSDoc typeParam + add support for TSDoc on constructors, variables, methodSignature

🐞 Bug Fixes

  • Apply union type optimisation on return type
  • Support typeAlias exporting a single typeParameters: type PluginFunc<T> = T;
  • If a property is decorated with ? and undefined or null only wrap it inside a single option
  • Handle symbol correctly to not emit a warning because of an unsupported kind
  • Generate a normal interface if a type literal has an IndexSignature

0.6.0 - 2024-05-08

πŸš€ Features

  • Support IntersectionType with UnionType of TypeLiteral
  • Replace "module" placeholder with "REPLACE_ME_WITH_MODULE_NAME"
  • Add support for NamedTuple

🐞 Bug Fixes

  • If no constructor is defined on an exported class generate a default one
  • Don't crash when encountering a TypeQuery against a module declaration
  • String enum containing a dot should be escaped
  • Allow resolution of keyOf as the return type of interface property
  • Don't assume that a node processed by keyof is always an interface, instead read it as standard node
  • Fix @glutinum/cli to include fable_modules in the output

0.5.0 - 2024-05-08

Fixed

  • Transform Promise to JS.Promise (by @nojaf) (GH-33)

  • Transform Uint8Array to JS.Uint8Array

  • Optional argument of F# Method are prefixed with ? instead of suffixing them with option

  • Sanitize names coming from TypeScript by removing surrounding quotes (", ')

  • String enums containing a - should be escaped with backtick (GH-44)

  • String enums starting with a number should be escaped with backtick (GH-43)

  • Optional interface properties should be transform into 'T option

  • Don't indent module name when printing the F# code

  • When leaving module scope, indent the printer memory

  • Don't crash when flattening a union

    export type LatLngTuple = [number, number, number?];
    
    export type LatLngExpression = string | LatLngTuple;
    type LatLngTuple = float * float * float option
    
    type LatLngExpression =
        U2<string, LatLngTuple>
  • Prevent infite loop when a class has a reference to a union type which reference the class itself

    export declare class MyClass {
        contains(otherBoundsOrLatLng: MyUnion | string): boolean;
    }
    
    export type MyUnion = MyClass | string;
    [<AllowNullLiteral>]
    [<Interface>]
    type MyClass =
        abstract member contains: otherBoundsOrLatLng: U2<MyUnion, string> -> bool
    
    type MyUnion =
        U2<MyClass, string>
  • Don't generate U1 if an union is resolved to a single type

    export type ColorInfo = number | false;
    // We can't represent false in F#
    type ColorInfo = float

Added

  • Add support for MethodSignature on interface (GH-28)

  • Ignore ExportAssignment as we don't know what to do with it yet

  • Add support for literal type alias (GH-45)

    type Mode = "auto";
    type Rank1 = 1;
    type Trusty = true;
    type Falsy = false;
    type PiValue = 3.14;
  • Add support for ThisType (GH-13)

  • Add support for FunctionType when used as a type

    export interface MyObject {
        instance: () => this;
        log: (a : Boolean, b : number) => this;
    }
    [<AllowNullLiteral>]
    type MyObject =
        abstract member instance: (unit -> MyObject) with get, set
        abstract member log: (bool -> float -> MyObject) with get, set
  • Add support for TupleType

  • Add support for TypeLiteral

    type Animal = {
        name: string;
    }
    [<AllowNullLiteral>]
    type Animal =
        abstract member name: string with get, set
  • Add support for IntersectionType

    interface ErrorHandling {
        success: boolean;
        error?: string;
    }
    
    interface ArtworksData {
        artworks: string[];
    }
    
    type ArtworksResponse = ArtworksData & ErrorHandling;
    [<AllowNullLiteral>]
    type ErrorHandling =
        abstract member success: bool with get, set
        abstract member error: string option with get, set
    
    [<AllowNullLiteral>]
    type ArtworksData =
        abstract member artworks: ResizeArray<string> with get, set
    
    [<AllowNullLiteral>]
    type ArtworksResponse =
        abstract member artworks: ResizeArray<string> with get, set
        abstract member success: bool with get, set
        abstract member error: string option with get, set
  • Add support for argument spread operator (GH-57)

  • Add support for { new (...args: any): any} (ConstructSignaure) (GH-59)

  • Add support for static member on classes (GH-60)

    export class Class {
        static methodA(): void;
    
        static methodB(arg1 : string, arg2: string): void;
    }
    [<AllowNullLiteral>]
    [<Interface>]
    type Class =
        static member inline methodA () =
            emitJsExpr () $$"""
    import { Class } from "module";
    Class.methodA()"""
        static member inline methodB (arg1: string, arg2: string) =
            emitJsExpr (arg1, arg2) $$"""
    import { Class } from "module";
    Class.methodB($0, $1)"""
  • Add support for more primitive TypeQuery (Any, String, Number, Bool, Any, Unit)

  • Add support for TypeQuery on a class declaration

  • Add support for propertyDeclaration on a class declaration

    declare class Fuse {
        public version: string
    }
    [<AllowNullLiteral>]
    [<Interface>]
    type Fuse =
        abstract member version: string with get, set

    Works also for static properties

    declare class Fuse {
        public static version: string
    }
    [<AllowNullLiteral>]
    [<Interface>]
    type Fuse =
        static member inline version
            with get () : string =
                emitJsExpr () $$"""
    import { Fuse } from "module";
    Fuse.version"""
            and set (value: string) =
                emitJsExpr (value) $$"""
    import { Fuse } from "module";
    Fuse.version = $0"""
  • Supports private static property

    export declare class SettingsContainer {
        static #privateField;
    }
    [<AllowNullLiteral>]
    [<Interface>]
    type SettingsContainer =
        static member inline private ``#privateField``
            with get () : unit =
                emitJsExpr () $$"""
    import { SettingsContainer } from "module";
    SettingsContainer.#privateField"""
            and set (value: unit) =
                emitJsExpr (value) $$"""
    import { SettingsContainer } from "module";
    SettingsContainer.#privateField = $0"""
  • Add support for optional type

    export type LatLngTuple = [number, number, number?];
    type LatLngTuple = float * float * float option
  • Add support for readonly TypeOperator

    export type ReadonlyArray<T> = readonly T[];
    type ReadonlyArray<'T> = ResizeArray<'T>
  • Optimise IntersectionType inside of TypeArguments

    export type RecordEntryObject = {
        v: string
        n: number
    }
    
    export type RecordEntryArrayItem = ReadonlyArray<
        RecordEntryObject & { i: number }
    >
    [<AllowNullLiteral>]
    [<Interface>]
    type RecordEntryObject =
        abstract member v: string with get, set
        abstract member n: float with get, set
    
    type RecordEntryArrayItem =
        ResizeArray<RecordEntryArrayItem.ReadonlyArray.ReturnType>
    
    module RecordEntryArrayItem =
    
        module ReadonlyArray =
    
            [<AllowNullLiteral>]
            [<Interface>]
            type ReturnType =
                abstract member v: string with get, set
                abstract member n: float with get, set
                abstract member i: float with get, set
  • Add support for default export assignment

  • Add support for object type alias

      ```ts
      export type MyObject = object;
      ```
    
      ```fs
      type MyObject = obj
      ```
    
  • Add support for converting tsdoc to xml doc comments

Changed

  • Replace Boolean with bool

  • Map Date type to JS.Date (GH-48)

  • Decorate all interface with [<Interface>] attribute this is to ensure they are erased at runtime even if they only have static member attached to them

  • Private field are not exposed in the F# code, because F# interface doesn't support them

    export declare class SettingsContainer {
        #privateField;
    }
    [<AllowNullLiteral>]
    [<Interface>]
    type SettingsContainer =
        interface end
  • Don't crash on unsupported syntax, instead we log the warning and continue the process. If needed, we default to obj

0.4.0 - 2024-01-08

Changed

  • Improve unsupported syntax error message to provide more context information (GH-26)

0.3.1 - 2024-01-02

Fixed

  • Respect CLI arguments casing (GH-23)

0.3.0 - 2024-01-01

Changed

  • Rework a bit the logged information

Fixed

  • Support TypeReference with generics

0.2.0 - 2023-12-30

Added

  • Basic CLI interface (help, version, options)
  • Ability to write the output to a file (use --out-file <file>)

Fixed

  • Map Date type to DateTime
  • Makes typescript part of the dependencies and not devDependencies

0.1.0 - 2023-12-29

Added

  • Initial release