TsBridge.Core
- Package
- purescript-ts-bridge
- Repository
- thought2/purescript-ts-bridge
#TsBridgeBy Source
class TsBridgeBy tok a where
A StandaloneTsType
represents a TypeScript type with everything it needs
to be placed inside complete TS program: If the type references nominal
types from other modules, all information is contained that is needed to
render those references.
Type Class that is used by the type generator to recursively traverse
types.
Instances for the specific types will be defined on the user's side with a
typeclass like this:
class TsBridge a where
tsBridge :: a -> StandaloneTsType
Then the internal type class is forwarded to the one of the user. For this you need to define a token data type and an instance like this:
data Tok = Tok
instance TsBridge a => TsBridgeBy Tok a where
tsBridgeBy _ = tsBridge
The token will then be passed to all generic functions of the library.
Members
tsBridgeBy :: tok -> Proxy a -> TsBridgeM TsType
#TsValues Source
class TsValues :: Type -> Row Type -> Constraint
class TsValues tok r where
Members
tsValues :: tok -> Record r -> TsBridgeM (Array TsDeclaration)
Instances
(TsValuesRL tok r rl, RowToList r rl) => TsValues tok r
#TsValuesRL Source
class TsValuesRL :: Type -> Row Type -> RowList Type -> Constraint
class TsValuesRL tok r rl where
Members
tsValuesRL :: tok -> Record r -> Proxy rl -> TsBridgeM (Array TsDeclaration)
Instances
TsValuesRL tok r Nil
(TsValuesRL tok r rl, TsBridgeBy tok a, Cons sym a rx r, IsSymbol sym) => TsValuesRL tok r (Cons sym a rl)
#tsModuleFile Source
tsModuleFile :: String -> Array (TsBridgeM (Array TsDeclaration)) -> Either AppError (Array TsModuleFile)
#tsOpaqueType Source
tsOpaqueType :: forall tok a. TsBridgeBy tok a => tok -> Proxy a -> TsBridgeM (Array TsDeclaration)
For rare cases where you want to manually export an opaque type. Once you export a value that contains a reference to this type, the type will be generated and exported automatically. Thus in most cases you don't need this.
#tsTypeAlias Source
tsTypeAlias :: forall tok a. TsBridgeBy tok a => tok -> String -> Proxy a -> TsBridgeM (Array TsDeclaration)
For rare cases where you want to export a type alias. References to this type alias will be fully resolved in the generated code. So it is more practical to use a newtype instead, which can be references by name.
#tsValue Source
tsValue :: forall tok a. TsBridgeBy tok a => tok -> String -> a -> TsBridgeM (Array TsDeclaration)
Exports a single PureScript value to TypeScript. tsValues
may be better choice.
Useful for declaring multiple PureScript values to be used by TypeScript. Through record punning the risk of exporting them with wrong names can be eliminated.
tsValues Tok { foo, bar, baz }