Skip to content

TypeScript to F#

What each TypeScript construct is generated as.

Declarations

TypeScriptF#
function f(): voidstatic member f () : unit on Exports, with Import
const x: numberstatic member inline x: float on Exports
class Cinterface C, and static member C () on Exports with EmitConstructor
static member of a classstatic member inline on the interface, emitted as JavaScript
interface I[<AllowNullLiteral>] [<Interface>] type I
type A = Btype A = B
namespace Nmodule N, its values on N.Exports
enum E { A = 1 }type E = A = 1
enum E { A = "a" }[<StringEnum>] type E = A
enum E { A = "a", B = 1 }[<Erase>] type E = String of string | Number of float, with a constant per member
export = fExports.f, through the default import
export default Cthe declaration, through the default import
export as namespace Nnothing
declare globala global_ module

Members

TypeScriptF#
x: Tabstract member x: T with get, set
readonly x: Tabstract member x: T with get
x?: Tabstract member x: T option with get, set
m(a: A): Rabstract member m: a: A -> R
m(a?: A)abstract member m: ?a: A -> R
m(...a: A[])[<ParamArray>] a: A []
get x(): T and set x(v: T)one property
[key: string]: T[<EmitIndexer>] abstract member Item: key: string -> T
new (a: A): R[<EmitConstructor>] abstract member Create: a: A -> R
(a: A): R call signature[<Emit("$0($1...)")>] abstract member Invoke: a: A -> R
m(this: T, a: A)abstract member m: a: A -> R
m<T>(a: T): Tabstract member m<'T>: a: 'T -> 'T
m<T = D>()the member, and an overload without T with D in its place
overloadsone member per overload

Types

TypeScriptF#
string, number, booleanstring, float, bool
bigintbigint
void, undefinedunit, obj
any, unknown, never, symbolobj
T[], Array<T>ResizeArray<T>
readonly T[]ReadonlyArray<T>, ResizeArray<T> as a parameter, a union case or a callback return
[A, B]A * B
[A, ...B[]]ResizeArray<obj>
type X = A | Ban erased union X with the cases X.A, X.B and the accessors AsA, AsB
A | B in a parameterone overload per case, up to 16 combinations, then U2<A, B>
A | B elsewhereU2<A, B>, up to U9
more than nine casesobj
"a" | B, literals and types

an erased union, its literals named and its types numbered

[<RequireQualifiedAccess>]
[<Erase(CaseRules.None)>]
type T =
    | a
    | Case1 of B
"a" | "b"a StringEnum type
1 | 2an enum type
true | falsebool
T | undefined, T | nullT option
(a: A) => RA -> R
(a: A, b: B) => Ra delegate of a: A * b: B -> R
type F = (a: A) => Rtype F = A -> R
{ x: T } in a parametera class with a ParamObject constructor
{ x: T } elsewherean interface in the module of the parent
DateDate of Glutinum.Types, built with Date.Create
Promise<T>, RegExpJS.Promise<T>, RegExp
Map<K, V>, Set<T>Map<K, V>, Set<T> from Fable.Core.JS
HTMLElement and the DOMGlutinum.Web.HTMLElement
Buffer and the Node APIGlutinum.Node.Buffer
typeof xthe type of x
keyof T, T knowna StringEnum of its keys
T[K], T knownthe type of the member
`on${K}`a StringEnum when it enumerates
x is Tbool
asserts x is Tunit
T extends U ? A : BA or B when decided, obj otherwise
Partial<T>the members of T, optional
Required<T>, Pick<T, K>, Omit<T, K>the members it keeps
Record<K, V>an interface with an indexer
Readonly<T>the members of T, read only
ReturnType<F>, Parameters<F>, Awaited<T>the resolved type
Exclude<T, undefined>T
a mapped type over a type parameterobj
a generic type parameter T extends C'T
Edit this page