> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nanoforge.eu/llms.txt
> Use this file to discover all available pages before exploring further.

# defineLibraryKey

> Declares a library's context key, tying its runtime key to the type-level Context augmentation so the two can't silently desync.

> **defineLibraryKey**\<`K`>(`key`): `K`

Defined in: [packages/common/src/library/define-library-key.ts:28](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/packages/common/src/library/define-library-key.ts#L28)

Declares a library's context key, tying its runtime key to the type-level
`Context` augmentation so the two can't silently desync.

## Type Parameters

### K

`K` *extends* `"app"` | `"vars"` | `"assets"` | `"viewport"`

## Parameters

### key

`K`

## Returns

`K`

## Remarks

Only accepts a key that is already a member of `Context` at the call
site — which means the library's own
`declare module "@nanoforge-dev/common" { interface Context { ... } }`
augmentation must be part of the same compilation unit. As a side effect, two libraries whose augmentations
declare the same key with incompatible shapes will fail to compile
together, catching accidental key collisions at build time.

## Example

```ts theme={null}
class MyLibrary extends Library {
  readonly key = defineLibraryKey("my");
}

declare module "@nanoforge-dev/common" {
  interface Context {
    my: MyContextApi;
  }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.