---
title: "typeKey(): function in Types, TypeShade API reference"
description: "typeKey, a function in Types. The runtime twin of KeyOf: turns any ShaderType value, literal or widened, into its canonical string key."
url: https://typeshade.dev/api/typekey/
language: en
---

# `typeKey()`

Function in Types

The runtime twin of KeyOf: turns any ShaderType value, literal or widened, into its canonical string key.

`import { typeKey } from 'typeshade'`
`import { typeKey } from 'typeshade/core/ir'`

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
function typeKey(t: ShaderType): string
```

## Parameters

**`t` `ShaderType`**

The type to spell.

## Return value

`string`

The canonical key string.

## Description

Error messages use it ([`SD0002`](https://typeshade.dev/reference/errors/sd0002/), [`SD0004`](https://typeshade.dev/reference/errors/sd0004/): “expected `vec3` , got `vec4` ”), and [`typeEq`](https://typeshade.dev/api/typeeq/) compares two types by it. Every `case` mirrors one arm of `KeyOf`; if they disagree, a value type-checks at author time but throws a spurious mismatch when the authoring code runs, or the reverse.

## Examples

### Example

```ts
import { typeKey } from 'typeshade'
import { vec3fT, texture2dArrayfT } from 'typeshade/core/ir'

typeKey(vec3fT) // 'vec3<f32>'
typeKey(texture2dArrayfT) // 'texture_2d_array<f32>'
```

## See also

- [`KeyOf`](https://typeshade.dev/api/keyof/)
- [`typeEq`](https://typeshade.dev/api/typeeq/)

## Source

[`src/core/ir/types.ts`, line 87](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/ir/types.ts#L87), at commit af54ddad5
