ts-plus
A description of ts-plus constructs
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
A description of ts-plus constructs
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
| name | ts-plus |
| description | A description of ts-plus constructs |
ts-plus is a custom modification of the TypeScript type-checker and compiler. It adds features such as:
Since it is a modification of the TypeScript compiler, LSP features will work as they normally do.
ts-plus uses JSDoc tags to communicate with the type-checker.
Lazy<A>The special Lazy type allows passing values where a thunk is expected. When compiled, the argument will be wrapped
in a thunk.
function f<A>(x: Lazy<A>): void {
x()
}
f(1)
When compiled, the call will be transformed to:
f(() => 1)
@tsplus type/**
* @tsplus type [identifier]
*/
Registers the symbol as a "type" within the ts-plus type system. Can be applied to type, interface, and class.
Extension methods and static values can be attached to instances of the type by referencing the identifier.
/**
* @tsplus type A
*/
export interface A {
x: number
}
/**
* @tsplus pipeable A add
*/
export function add(n: number) {
return (self: A): A => ({ x: self.x + n })
}
const a0: A = { x: 1 }
// `add` now exists as a callable function on `A`
const a1 = a.add(1) // { x: 2 }
@tsplus companion/**
* @tsplus companion [identifier]
*/
Registers the symbol as a "companion object" within the ts-plus type system. Can be applied to type, interface,
and class. Extension methods and static values can be attached to the symbol itself.
/**
* @tsplus companion AOps
*/
export interface A {
x: number
}
/**
* @tsplus static AOps make
*/
export function make(n: number) {
return { x: n }
}
// `make` now exists as a static function attached to the symbol `A`
const a = A.make(1) // { x: 1 }
@tsplus fluent/**
* @tsplus fluent [identifier] [name]
*/
Attaches a fluent-style function to a registered [identifier] using the name [name]. A fluent-style function is
one that takes the reciever as the first argument.
/**
* @tsplus type A
*/
export interface A {
x: number
}
/**
* @tsplus fluent A add
*/
export function add(self: A, n: number) {
return { x: self.x + n }
}
const a0: A = { x: 1 }
// `add` now exists as a callable function on instances of `A`
const a1 = a.add(1) // { x: 2 }
When compiled, the call will be transformed into:
const a1 = add(a, 1)
@tsplus pipeable/**
* @tsplus fluent [identifier] [name]
*/
Attaches a pipeable fluent-style function to a registered [identifier] using the name [name].
A pipeable fluent-style function is one that takes the reciever as a final curried argument.
/**
* @tsplus type A
*/
export interface A {
x: number
}
/**
* @tsplus pipeable A add
*/
export function add(n: number) {
return (self: A): A => ({ x: self.x + n })
}
const a0: A = { x: 1 }
// `add` now exists as a callable function on instances of `A`
const a1 = a.add(1) // { x: 2 }
When compiled, the call will be transformed into:
const a1 = add(1)(a)
@tsplus static/**
* @tsplus static [identifier] [name]
*/
Attaches a function or value to a registered [identifier] using the name [name].
/**
* @tsplus companion ListOps
*/
export class List {}
/**
* @tsplus static ListOps empty
*/
export function empty(): List {
return new List()
}
// `empty` now exists as a callable function on `List`
const a = List.empty()
When compiled, the call will be transformed into:
const a = empty()
Special static name "__call"
__call is a special name used to signify that the function should be attached to the call signature of the symbol.
/**
* @tsplus companion ListOps
*/
export class List {}
/**
* @tsplus static ListOps __call
*/
export function empty(): List {
return new List()
}
// `empty` is now attached to the call signature of the `List` symbol
const a = List()
When compiled, the call will be transformed into:
const a = empty()
@tsplus getter/**
* @tsplus getter [identifier] [name]
*/
Attaches a getter-style function to a registered [identifier] using the name [name].
Getter-style functions are ones that take only the reciever as input.
/**
* @tsplus type Array
*/
export class Array<A> {}
/**
* @tsplus getter Array head
*/
export function head<A>(self: List<A>): A | undefined {
return self.head
}
const array = [1, 2, 3]
// `head` now exists as a getter on `Array`
const a = array.head
When compiled, the call will be transformed into:
const a = head(array)
@tsplus global/**
* @tsplus global
*/
import { x } from "@org/module"
Makes an import globally available to all sources.