parametric types for typescript

This commit is contained in:
Umur Ozkul 2022-08-17 21:22:10 +02:00
parent 55c03ed520
commit 868f9f428a
5 changed files with 24 additions and 23 deletions

View File

@ -9,7 +9,7 @@ open Expect.Operators
describe("ReducerProject Tutorial", () => { describe("ReducerProject Tutorial", () => {
describe("Single source", () => { describe("Single source", () => {
/* /*
Case "Running a single source". Case "Running a single source".
*/ */
test("run", () => { test("run", () => {
@ -98,7 +98,7 @@ Case "Running a single source".
//TODO multiple sources //TODO multiple sources
//TODO multiple sources with includes. Introduction to includes //TODO multiple sources with includes. Introduction to includes
//TODO multiple sources with multi level includes. Cycle detection //TODO multiple sources with multi level includes. Cycle detection
//TODO //TODO
//TODO: Implement a runOrder consideration - clean results based on run order. //TODO: Implement a runOrder consideration - clean results based on run order.
//TODO: runOrder vs setSource/touchSource //TODO: runOrder vs setSource/touchSource
//TODO: Advanced details: (below) //TODO: Advanced details: (below)
@ -106,4 +106,4 @@ Case "Running a single source".
//TODO: dependents and reexecution //TODO: dependents and reexecution
//TODO: dependencies and reexecution //TODO: dependencies and reexecution
//TODO: cleanAllResults clean //TODO: cleanAllResults clean
//TODO: cleanAll clean //TODO: cleanAll clean

View File

@ -1,4 +1,5 @@
open ForTS_Types open ForTS_Types
@genType @genType
let getResult = (_p: myProject): option<result_internalValue> => My_ErrorValue.EError->Error->Some let getResult = (_p: myProject): option<result_<internalValue, errorValue>> =>
My_ErrorValue.EError->Error->Some

View File

@ -0,0 +1,18 @@
open ForTS_Types
@genType let isError = (r: result_<'a, 'e>): bool => Belt.Result.isError(r)
@genType let isOk = (r: result_<'a, 'e>): bool => Belt.Result.isOk(r)
@genType
let getError = (r: result_<'a, 'e>): option<'e> =>
switch r {
| Ok(_) => None
| Error(e) => Some(e)
}
@genType
let getValue = (r: result_<'a, 'e>): option<'a> =>
switch r {
| Ok(v) => Some(v)
| Error(_) => None
}

View File

@ -1,18 +0,0 @@
open ForTS_Types
@genType let isError = (r: result_internalValue): bool => Belt.Result.isError(r)
@genType let isOk = (r: result_internalValue): bool => Belt.Result.isOk(r)
@genType
let getError = (r: result_internalValue): option<errorValue> =>
switch r {
| Ok(_) => None
| Error(e) => Some(e)
}
@genType
let getValue = (r: result_internalValue): option<internalValue> =>
switch r {
| Ok(v) => Some(v)
| Error(_) => None
}

View File

@ -6,7 +6,7 @@
@genType.opaque type recordLike = MyInterface_InternalValue_RecordLike.t @genType.opaque type recordLike = MyInterface_InternalValue_RecordLike.t
@genType.opaque type internalVoid = int @genType.opaque type internalVoid = int
@genType.opaque type errorValue = My_ErrorValue.t @genType.opaque type errorValue = My_ErrorValue.t
@genType.opaque type result_internalValue = result<internalValue, errorValue> // There has to be a type for each result permutation @genType.opaque type result_<'a, 'e> = result<'a, 'e> // There has to be a type for each result permutation
@genType.opaque type myProject = {name: string} @genType.opaque type myProject = {name: string}
//There is no need to map option<> as it becomes nullable //There is no need to map option<> as it becomes nullable