Skip to content

Commit

Permalink
Partial fix of #386: Handle ArrayLike & PromiseLike (#387)
Browse files Browse the repository at this point in the history
`ArrayLike` -> `System.Collections.Generic.IList<'T>`
`PromiseLike` -> `Fable.Core.JS.Promise<'T>`
  • Loading branch information
Booksbaum authored Mar 10, 2021
1 parent 32a1a94 commit 6f4017c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/transform.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,8 @@ let abbrevTypes =
"Function", "type Function = System.Action"
"Symbol", "type Symbol = obj"
"TemplateStringsArray", "type TemplateStringsArray = System.Collections.Generic.IReadOnlyList<string>"
"ArrayLike", "type ArrayLike<'T> = System.Collections.Generic.IList<'T>"
"PromiseLike", "type PromiseLike<'T> = Fable.Core.JS.Promise<'T>"
] |> Map.ofList

let fixFsFileOut fo =
Expand Down
4 changes: 4 additions & 0 deletions test/fragments/regressions/#386-TS-types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface I {
a(v: PromiseLike<string>): PromiseLike<number>;
b(v: ArrayLike<string>): ArrayLike<number>;
}
13 changes: 13 additions & 0 deletions test/fragments/regressions/#386-TS-types.expected.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// ts2fable 0.0.0
module rec ``#386-TS-types``
open System
open Fable.Core
open Fable.Core.JS

type ArrayLike<'T> = System.Collections.Generic.IList<'T>
type PromiseLike<'T> = Fable.Core.JS.Promise<'T>


type [<AllowNullLiteral>] I =
abstract a: v: PromiseLike<string> -> PromiseLike<float>
abstract b: v: ArrayLike<string> -> ArrayLike<float>
4 changes: 4 additions & 0 deletions test/fsFileTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -508,4 +508,8 @@ let testFsFileLines tsPaths fsPath (f: string list -> unit) =
it "regression #382 package with hyphen in name produces invalid module name with hyphen" <| fun _ ->
runRegressionTest "#382-package-with-hyphen-in-name-produces-invalid-module-name-with-hyphen"

// https://github.com/fable-compiler/ts2fable/issues/386
it "regression #386 TS types" <| fun _ ->
runRegressionTest "#386-TS-types"

)?timeout(15_000)

0 comments on commit 6f4017c

Please sign in to comment.