Node reference | typescript-transformer | Spatie

 SPATIE

  TypeScript Transformer
=========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Typescript-transformer](https://spatie.be/docs/typescript-transformer/v3)  Typescript-nodes  Node reference

 Version   v3   v2   v1

 Other versions for crawler [v3](https://spatie.be/docs/typescript-transformer/v3) [v2](https://spatie.be/docs/typescript-transformer/v2) [v1](https://spatie.be/docs/typescript-transformer/v1)

  Node reference
- [ Introduction ](https://spatie.be/docs/typescript-transformer/v3/introduction)
- [ Postcardware ](https://spatie.be/docs/typescript-transformer/v3/postcardware)
- [ Installation ](https://spatie.be/docs/typescript-transformer/v3/installation)
- [ Questions &amp; issues ](https://spatie.be/docs/typescript-transformer/v3/questions-and-issues)
- [ Changelog ](https://spatie.be/docs/typescript-transformer/v3/changelog)
- [ About us ](https://spatie.be/docs/typescript-transformer/v3/about-us)

Getting started
---------------

- [ Setting up ](https://spatie.be/docs/typescript-transformer/v3/getting-started/setting-up)
- [ Running TypeScript Transformer for the first time ](https://spatie.be/docs/typescript-transformer/v3/getting-started/first-run)
- [ Special attributes ](https://spatie.be/docs/typescript-transformer/v3/getting-started/attributes)
- [ Typing properties ](https://spatie.be/docs/typescript-transformer/v3/getting-started/typing-properties)
- [ Replacing common types ](https://spatie.be/docs/typescript-transformer/v3/getting-started/replacing-types)
- [ Formatters ](https://spatie.be/docs/typescript-transformer/v3/getting-started/formatters)

Laravel
-------

- [ Installation and setup ](https://spatie.be/docs/typescript-transformer/v3/laravel/installation-and-setup)
- [ Laravel Data ](https://spatie.be/docs/typescript-transformer/v3/laravel/laravel-data)
- [ Controllers ](https://spatie.be/docs/typescript-transformer/v3/laravel/controllers)
- [ Routes ](https://spatie.be/docs/typescript-transformer/v3/laravel/routes)
- [ Route filters ](https://spatie.be/docs/typescript-transformer/v3/laravel/route-filters)
- [ Watch mode ](https://spatie.be/docs/typescript-transformer/v3/laravel/watch-mode)

Custom transformers
-------------------

- [ Getting started ](https://spatie.be/docs/typescript-transformer/v3/transformers/getting-started)
- [ Class transformer ](https://spatie.be/docs/typescript-transformer/v3/transformers/class-transformer)
- [ Enum transformer ](https://spatie.be/docs/typescript-transformer/v3/transformers/enum-transformer)

Transformed providers
---------------------

- [ Getting started ](https://spatie.be/docs/typescript-transformer/v3/providers/getting-started)
- [ Using different writers in providers ](https://spatie.be/docs/typescript-transformer/v3/providers/writers-in-providers)
- [ Logging in providers ](https://spatie.be/docs/typescript-transformer/v3/providers/logging)
- [ Referencing types ](https://spatie.be/docs/typescript-transformer/v3/providers/references)
- [ Helpers ](https://spatie.be/docs/typescript-transformer/v3/providers/helpers)

TypeScript nodes
----------------

- [ Introduction ](https://spatie.be/docs/typescript-transformer/v3/typescript-nodes/introduction)
- [ Building your own TypeScript node ](https://spatie.be/docs/typescript-transformer/v3/typescript-nodes/custom-nodes)
- [ Visiting TypeScript nodes ](https://spatie.be/docs/typescript-transformer/v3/typescript-nodes/visitor)
- [ Node reference ](https://spatie.be/docs/typescript-transformer/v3/typescript-nodes/reference)

Watch mode
----------

- [ How does it work? ](https://spatie.be/docs/typescript-transformer/v3/watch-mode/how-it-works)
- [ Setting up the runner ](https://spatie.be/docs/typescript-transformer/v3/watch-mode/setting-up-the-runner)
- [ Watch events ](https://spatie.be/docs/typescript-transformer/v3/watch-mode/watch-events)
- [ PHP Nodes ](https://spatie.be/docs/typescript-transformer/v3/watch-mode/php-nodes)

Advanced
--------

- [ Extensions ](https://spatie.be/docs/typescript-transformer/v3/advanced/extensions)
- [ Managing transformers ](https://spatie.be/docs/typescript-transformer/v3/advanced/managing-transformers)
- [ Loggers ](https://spatie.be/docs/typescript-transformer/v3/advanced/loggers)
- [ Custom writers ](https://spatie.be/docs/typescript-transformer/v3/advanced/custom-writers)

 Node reference
==============

###  On this page

1. [ Types ](#content-types)
2. [ Objects &amp;amp; Interfaces ](#content-objects--interfaces)
3. [ Declarations &amp;amp; Expressions ](#content-declarations--expressions)
4. [ Building Blocks ](#content-building-blocks)

A quick reference of all available TypeScript AST nodes.

Types
-----------------------------------------------------------------------

### Primitives

NodeOutput`new TypeScriptString()``string``new TypeScriptNumber()``number``new TypeScriptBoolean()``boolean``new TypeScriptNull()``null``new TypeScriptUndefined()``undefined``new TypeScriptVoid()``void``new TypeScriptNever()``never``new TypeScriptUnknown()``unknown``new TypeScriptAny()``any`### Combining Types

**TypeScriptUnion** — `string | number`

```
new TypeScriptUnion([new TypeScriptString(), new TypeScriptNumber()])
```

**TypeScriptIntersection** — `A & B`

```
new TypeScriptIntersection([new TypeScriptIdentifier('A'), new TypeScriptIdentifier('B')])
```

**TypeScriptArray** — `string[]`

```
new TypeScriptArray([new TypeScriptString()])
```

**TypeScriptTuple** — `[string, number]`

```
new TypeScriptTuple([new TypeScriptString(), new TypeScriptNumber()])
```

### Generics

**TypeScriptGeneric** — `Record`

Used both for generic type *usage* (concrete type arguments) and generic type *declarations* (with `TypeScriptGenericTypeParameter` arguments).

```
// Usage: Record
new TypeScriptGeneric(new TypeScriptIdentifier('Record'), [new TypeScriptString(), new TypeScriptNumber()])

// Declaration: Container
new TypeScriptGeneric(new TypeScriptIdentifier('Container'), [
    new TypeScriptGenericTypeParameter(new TypeScriptIdentifier('T'), extends: new TypeScriptIdentifier('object')),
])
```

**TypeScriptGenericTypeParameter** — `T`, `T extends string`, `T extends string = string`

Declares a generic type variable with optional constraint and default. Used inside `TypeScriptGeneric` for type declarations.

```
// Bare: T
new TypeScriptGenericTypeParameter(new TypeScriptIdentifier('T'))

// With constraint: T extends string
new TypeScriptGenericTypeParameter(new TypeScriptIdentifier('T'), extends: new TypeScriptString())

// With constraint and default: T extends string = string
new TypeScriptGenericTypeParameter(new TypeScriptIdentifier('T'), extends: new TypeScriptString(), default: new TypeScriptString())
```

### Advanced Type Operators

**TypeScriptConditional** — `T extends string ? number : boolean`

```
new TypeScriptConditional(
    TypeScriptOperator::extends(new TypeScriptIdentifier('T'), new TypeScriptString()),
    new TypeScriptNumber(),
    new TypeScriptBoolean(),
)
```

**TypeScriptMappedType** — `{ [K in keyof T]: T[K] }`

```
// Simple: { [K in keyof T]: T[K] }
new TypeScriptMappedType(
    'K',
    TypeScriptOperator::keyof(new TypeScriptIdentifier('T')),
    new TypeScriptIndexedAccess(new TypeScriptIdentifier('T'), [new TypeScriptIdentifier('K')]),
)

// With modifiers: { readonly [K in keyof T]?: T[K] }
new TypeScriptMappedType(
    'K',
    TypeScriptOperator::keyof(new TypeScriptIdentifier('T')),
    new TypeScriptIndexedAccess(new TypeScriptIdentifier('T'), [new TypeScriptIdentifier('K')]),
    readonlyModifier: 'readonly',
    optionalModifier: '?',
)
```

**TypeScriptIndexedAccess** — `User["name"]`

```
new TypeScriptIndexedAccess(new TypeScriptIdentifier('User'), [new TypeScriptLiteral('name')])
```

**TypeScriptOperator** — `keyof T`, `typeof config`, `T extends U`

```
TypeScriptOperator::keyof(new TypeScriptIdentifier('T'))
TypeScriptOperator::typeof(new TypeScriptIdentifier('config'))
TypeScriptOperator::extends(new TypeScriptIdentifier('T'), new TypeScriptIdentifier('U'))
```

**TypeScriptCallable** — `(...args: any[]) => any` or custom function types like `(x: string) => void`

```
new TypeScriptCallable() // (...args: any[]) => any
new TypeScriptCallable([new TypeScriptParameter('x', new TypeScriptString())], new TypeScriptVoid()) // (x: string) => void
```

Objects &amp; Interfaces
----------------------------------------------------------------------------------------------------------------------

**TypeScriptObject** — `{ name: string }`

For describing object type shapes in type annotations. Compare with `TypeScriptObjectLiteral` for value-level JSON objects.

```
new TypeScriptObject([new TypeScriptProperty('name', new TypeScriptString())])
```

**TypeScriptProperty** — `readonly name?: string`

```
new TypeScriptProperty('name', new TypeScriptString(), isOptional: true, isReadonly: true)
```

**TypeScriptIndexSignature** — `[key: string]`

```
new TypeScriptIndexSignature(new TypeScriptString(), 'key')
```

**TypeScriptInterface** — `interface User { name: string; greet(): void; }`

```
new TypeScriptInterface('User', [new TypeScriptProperty('name', new TypeScriptString())], [new TypeScriptMethodSignature('greet', [], new TypeScriptVoid())])
```

**TypeScriptMethodSignature** — `getName(id: number): string;`

```
new TypeScriptMethodSignature('getName', [new TypeScriptParameter('id', new TypeScriptNumber())], new TypeScriptString())
```

Declarations &amp; Expressions
----------------------------------------------------------------------------------------------------------------------------------------

### Declarations

**TypeScriptAlias** — `type Name = string;`

```
new TypeScriptAlias('Name', new TypeScriptString())
// or with explicit identifier: new TypeScriptAlias(new TypeScriptIdentifier('Name'), new TypeScriptString())
```

**TypeScriptEnum** — `enum Status { Active = 'active' }`

```
new TypeScriptEnum('Status', [['name' => 'Active', 'value' => 'active']])
```

**TypeScriptFunctionDeclaration** — `function greet(name: string): string { ... }`

```
new TypeScriptFunctionDeclaration('greet', [new TypeScriptParameter('name', new TypeScriptString())], new TypeScriptString(), new TypeScriptRaw('return name;'))
```

**TypeScriptVariableDeclaration** — `const name = "world"`

```
TypeScriptVariableDeclaration::const('name', new TypeScriptLiteral('world'))
```

**TypeScriptOperator::export()** — `export type Name = string;`

```
TypeScriptOperator::export(new TypeScriptAlias('Name', new TypeScriptString()))
```

**TypeScriptImport** — `import { User as AppUser } from './types';`

```
new TypeScriptImport('./types', [['name' => 'User', 'alias' => 'AppUser']])
```

**TypeScriptNamespace** — `declare namespace App { namespace Models { ... } }` or `namespace Models { ... }`

```
new TypeScriptNamespace('App', [$typeNode], children: [
    new TypeScriptNamespace('Models', [$otherTypeNode], declare: false)
])
```

### Expressions

Value-level nodes that produce JavaScript/TypeScript expressions. Some output similar syntax to type-level nodes but serve a different purpose.

**TypeScriptCallExpression** — `createAction("index")`

```
new TypeScriptCallExpression(new TypeScriptIdentifier('createAction'), [new TypeScriptLiteral('index')], genericTypes: [new TypeScriptIdentifier('UserParams')])
```

**TypeScriptArrayExpression** — `["a", "b", "c"]`

For array literals in expressions. Compare with `TypeScriptTuple` for type-level tuples.

```
new TypeScriptArrayExpression([new TypeScriptLiteral('a'), new TypeScriptLiteral('b'), new TypeScriptLiteral('c')])
```

**TypeScriptObjectLiteral** — `{ "method": "GET", "url": "/users" }`

For JSON object values. Compare with `TypeScriptObject` for type-level object shapes.

```
new TypeScriptObjectLiteral(['method' => 'GET', 'url' => '/users'])
```

Building Blocks
-----------------------------------------------------------------------------------------------------

Low-level nodes used as parts of other nodes.

**TypeScriptIdentifier** — `MyType` (auto-quotes invalid identifiers)

```
new TypeScriptIdentifier('MyType')
```

**TypeScriptLiteral** — `"hello"`, `42`, `true`

```
new TypeScriptLiteral('hello')
```

**TypeScriptParameter** — `name?: string`, `...args: string[]`

```
new TypeScriptParameter('name', new TypeScriptString(), isOptional: true)
```

**TypeScriptRaw** — pass-through raw TypeScript, supports `references` for `%placeholder%` substitution and `additionalImports` for external TS file imports

```
new TypeScriptRaw('Record')
new TypeScriptRaw('%User% | null', references: ['User' => UserData::class])
```

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
