# TS1162: An object member cannot be declared optional.

> A method or property in an object literal is marked optional with `?`. Optional markers belong in types, not in object literals.

## What it means

In an object literal every member exists, so `?` after a member name has no meaning. Optional
members are declared in the object's type (an interface or type literal).

## Example

```ts
export const o = { a?() { return 1; } };
```

## How to fix

- Remove the `?`.
- Declare the optional member in a type and annotate the object with it: `const o: { a?(): number } = {}`.

Source: https://ts-r.dev/errors/TS1162/
