> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt. # Adding custom code > Learn how to add custom logic, methods, and dependencies to your TypeScript SDK with Fern. Extend generated clients easily. #### Enterprise feature This feature is available only for the [Enterprise plan](https://buildwithfern.com/pricing). To get started, reach out to [support@buildwithfern.com](mailto:support@buildwithfern.com). This page covers how to add custom logic, methods, and dependencies to your TypeScript SDK. ## Adding custom logic To get started adding custom code: These steps cover adding a new custom file to the SDK. To preserve line-level edits to a generated file, use [Replay](/learn/sdks/overview/custom-code#replay) instead. ### Create a new file and add your custom logic **`src/helper.ts`** ```typescript title="src/helper.ts" export function myHelper(): void { return console.log("Hello world!"); } ``` ### Add your file to `.fernignore` **`.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(); ``` #### Advanced: Custom import paths By default, the TypeScript generator only auto-generates `exports` entries in `package.json` for your API definition. If you want consumers to import your custom file via a dedicated subpath (e.g. `import { myHelper } from "@acme/sdk/helper"`), you must register it manually using [`packageJson.exports`](/learn/sdks/generators/typescript/configuration#packagejson) in `generators.yml`: **`generators.yml`** ```yaml {5-14} title="generators.yml" - name: fern-typescript-sdk version: 3.95.1 config: packageJson: exports: "./helper": # consumer import path — not the source file path types: "./dist/cjs/helper.d.ts" import: types: "./dist/esm/helper.d.mts" default: "./dist/esm/helper.mjs" require: types: "./dist/cjs/helper.d.ts" default: "./dist/cjs/helper.js" ``` The export key (e.g., `"./helper"`) determines the import path your users will use and doesn't need to match the source file path. These entries are merged into the generated `exports`, so they persist across regenerations. Since Node.js [enforces the `exports` map](https://nodejs.org/api/packages.html#package-entry-points), custom files aren't importable via a subpath until you add them here. ## 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. See an example from Flatfile using this process in their [TypeScript SDK](https://github.com/FlatFilers/flatfile-node) ### 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. **`src/wrapper/MyClient.ts`** ```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!"); } } ``` See an example from Flatfile doing this in their [FlatfileClient](https://github.com/FlatFilers/flatfile-node/blob/main/src/wrapper/FlatfileClient.ts) ### Export the extended client Update your `index.ts` file to export the **extended client** instead of the generated client. **`src/index.ts`** ```typescript title="src/index.ts" export { MyClient } from "src/wrapper/MyClient"; // instead of "src/client" ``` See an example [index.ts](https://github.com/FlatFilers/flatfile-node/blob/main/src/index.ts) from Flatfile ### Update `.fernignore` Add both the `wrapper` directory and `index.ts` to `.fernignore`. **`.fernignore`** ```diff title=".fernignore" + src/wrapper + src/index.ts ``` See an example [.fernignore](https://github.com/FlatFilers/flatfile-node/blob/main/.fernignore) from Flatfile ### Consume the method Now your users can consume the helper function by importing it from the SDK. ```typescript client.myHelper() ``` ## Custom dependencies To add packages that your custom code requires, use the [`extraDependencies`](/learn/sdks/generators/typescript/configuration#extraDependencies) and [`extraDevDependencies`](/learn/sdks/generators/typescript/configuration#extraDevDependencies) options in your `generators.yml`. **`generators.yml`** ```yaml {4-7} title="generators.yml" - name: fern-typescript-sdk version: 3.95.1 config: extraDependencies: lodash-es: '1.0.0' extraDevDependencies: "@types/lodash-es": '1.0.0' ``` > Learn how to add custom logic, methods, and dependencies to your TypeScript SDK with Fern. Extend generated clients easily.