# Adding custom code

> Learn how to add custom logic, methods, and dependencies to your TypeScript SDK with Fern. Extend generated clients easily.

This page covers how to add custom logic, methods, and dependencies to your TypeScript SDK.

<Info>
  Before getting started, 

  [read about how Fern SDKs use custom code and learn about the `.fernignore` file](/sdks/overview/custom-code)

  .
</Info>

## Adding custom logic

To get started adding custom code:

<Steps>
  ### Create a new file and add your custom logic

  ```typescript title="src/helper.ts"
  export function myHelper(): void {
      return console.log("Hello world!");
  }
  ```

  ### Add your file to `.fernignore`

  ```yaml {3} title=".fernignore"
  # Specify files that shouldn't be modified by Fern

  src/helper.ts
  ```

  ### Consume the helper

  Now your users can consume the helper function by importing it from the SDK.

  ```typescript
  import { myHelper } from "sdk/helper";

  myHelper();
  ```
</Steps>

## Custom SDK methods

Fern also allows you to add custom methods to the SDK itself (e.g.
`client.my_method()` ) by inheriting the Fern generated client and then
extending it.

<Note>
  See an example from Flatfile using this process in their [TypeScript SDK](https://github.com/FlatFilers/flatfile-node)
</Note>

<Steps>
  ### Import and extend the generated client

  First, import the Fern generated client from `../client` and alias it to `FernClient`.
  Next, extend `FernClient` and add whatever methods you want.

  ```typescript title="src/wrapper/MyClient.ts"
  import { MyClient as FernClient } from "../client"; // alias the Fern generated client

  export class MyClient extends FernClient { // extend the Fern generated client

    public myHelper(): void {
      console.log("Hello world!");
    }

  }
  ```

  <Note>
    See an example from Flatfile doing this in their [FlatfileClient](https://github.com/FlatFilers/flatfile-node/blob/main/src/wrapper/FlatfileClient.ts)
  </Note>

  ### Export the extended client

  Update your `index.ts` file to export the **extended client** instead of the generated client.

  ```typescript title="src/index.ts"
  export { MyClient } from "src/wrapper/MyClient"; // instead of "src/client"
  ```

  <Note>
    See an example [index.ts](https://github.com/FlatFilers/flatfile-node/blob/main/src/index.ts) from Flatfile
  </Note>

  ### Update `.fernignore`

  Add both the `wrapper` directory and `index.ts` to `.fernignore`.

  ```diff title=".fernignore"
  + src/wrapper
  + src/index.ts
  ```

  <Note>
    See an example [.fernignore](https://github.com/FlatFilers/flatfile-node/blob/main/.fernignore) from Flatfile
  </Note>

  ### Consume the method

  Now your users can consume the helper function by importing it from the SDK.

  ```typescript
  client.myHelper()
  ```
</Steps>

## Custom dependencies

<Warning title="Pro and Enterprise feature">
  This feature is available only for the [Pro and Enterprise plans](https://buildwithfern.com/pricing). To get started, reach out to [support@buildwithfern.com](mailto:support@buildwithfern.com).
</Warning>

To add packages that your custom code requires, update your `generators.yml`.

```yaml {4-7} title="generators.yml"
- name: fernapi/fern-typescript-sdk
  version: 3.46.3
  config:
    extraDependencies:
      lodash-es: '1.0.0'
    extraDevDependencies:
      "@types/lodash-es": '1.0.0'
```