Module

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

#TsValues Source

class TsValues :: Type -> Row Type -> Constraintclass TsValues tok r  where

Members

  • tsValues :: tok -> Record r -> TsBridgeM (Array TsDeclaration)

    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 }

Instances

#TsValuesRL Source

class TsValuesRL :: Type -> Row Type -> RowList Type -> Constraintclass TsValuesRL tok r rl  where

Members

Instances

#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.