# What's the optimal way to use TypeScript?

**URL:** <https://community.fibery.io/t/whats-the-optimal-way-to-use-typescript/8233>\
**Category:** API & Programming\
**Created:** [February 7, 2025, 7:50am UTC](https://community.fibery.io/t/whats-the-optimal-way-to-use-typescript/8233 "2025-02-07T07:50:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ooker](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/ooker/32/7033_2.png) [@Ooker](https://community.fibery.io/u/Ooker)\
**Post date:** [February 7, 2025, 7:50am UTC](https://community.fibery.io/t/whats-the-optimal-way-to-use-typescript/8233/1 "2025-02-07T07:50:19Z")

</div>

How do you use TypeScript when writing automation script or using APIs?

Here is my type:

```ts
// deno-lint-ignore-file no-explicit-any
export type Id = string;
export interface TrườngFibery<T> {
  Name: T;
  Id: Id;
}

export interface DescriptionFibery {
  Secret: string;
  Id: Id;
}

export interface EntityFibery {
  Name: string;
  Description?: DescriptionFibery;
  Type: string;
  "Public Id": string;
  Id: string;
  "Created By": TrườngFibery<string>;
  "Creation Date": string;
  "Modification Date": string;
  Rank: number;
}
export type EntityFiberyToCreate = Partial<EntityFibery>;

export interface ArgsFibery {
  steps: [];
  currentEntities: EntityFibery[];
  currentUser: {
    "Public Id": string;
    Id: Id;
    Email: string;
    "Active?": boolean;
    "Admin?": boolean;
    "Guest?": boolean;
    "Creation Date": string;
    "Modification Date": string;
  };
}

export interface ContextFibery {
  getService: (service: "fibery" | "http" | "utils") => FiberyService | HttpService | UtilsService;
}

export interface FiberyService {
  getEntityById: (type: string, id: string, fields: string[]) => any;
  getEntitiesByIds: (type: string, ids: string[], fields: string[]) => { Id: string; [key: string]: string }[];
  createEntity: (type: string, values: object) => any;
  createEntityBatch: (type: string, entities: object[]) => any;
  updateEntity: (type: string, id: string, values: object) => any;
  updateEntityBatch: (type: string, entities: object[]) => any;
  addCollectionItem: (type: string, id: string, field: string, itemId: string) => any;
  addCollectionItemBatch: (type: string, field: string, args: { id: Id; itemId: string }[]) => any;
  removeCollectionItem: (type: string, id: string, field: string, itemId: string) => any;
  removeCollectionItemBatch: (type: string, field: string, args: { id: Id; itemId: string }[]) => any;
  deleteEntity: (type: string, id: string) => any;
  deleteEntityBatch: (type: string, ids: string[]) => any;
  setState: (type: string, id: string, state: string) => any;
  setStateToFinal: (type: string, id: string) => any;
  assignUser: (type: string, id: string, userId: string) => any;
  unassignUser: (type: string, id: string, userId: string) => any;
  getDocumentContent: (secret: string, format: string) => any;
  setDocumentContent: (secret: string, content: string, format: string) => any;
  appendDocumentContent: (secret: string, content: string, format: string) => any;
  addComment: (type: string, id: string, comment: string, authorId: string, format: string) => any;
  addFileFromUrl: (url: string, fileName: string, type: string, id: string, headers: object) => any;
  executeAction: (action: string, type: string, args: [object]) => any;
  executeSingleCommand: (command: FiberyCommand) => any;
  graphql: (spacename: string, command: string) => any;
  getSchema: () => any;
}

export interface HttpService {
  getAsync: (url: string, options?: { headers?: { [key: string]: string } }) => any;
  postAsync: (url: string, options?: { body?: any; headers?: { [key: string]: string } }) => any;
  putAsync: (url: string, options?: { body?: any; headers?: { [key: string]: string } }) => any;
  deleteAsync: (url: string, options?: { body?: any; headers?: { [key: string]: string } }) => any;
}

export interface UtilsService {
  getEntityUrl: (type: string, publicId: string) => any;
  getFileUrl: (fileSecret: string) => any;
  uuid: () => any;
}

```

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [February 7, 2025, 7:59am UTC](https://community.fibery.io/t/whats-the-optimal-way-to-use-typescript/8233/2 "2025-02-07T07:59:04Z")

</div>

> [@Ooker](#):
>
> How do you use TypeScript when writing automation script or using APIs?

You can’t use TS in Fibery

---

<div class="post-metadata">

**Author:** ![Ooker](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/ooker/32/7033_2.png) [@Ooker](https://community.fibery.io/u/Ooker)\
**Post date:** [February 7, 2025, 3:41pm UTC](https://community.fibery.io/t/whats-the-optimal-way-to-use-typescript/8233/3 "2025-02-07T15:41:05Z")

</div>

I know, but internally you use TS. That’s why you can have auto-suggestion on the automation code editor. So can you share how you work with TS?

---

<div class="post-metadata">

**Author:** ![Sergey\_Truhtanov](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/sergey_truhtanov/32/13986_2.png) [@Sergey\_Truhtanov](https://community.fibery.io/u/Sergey_Truhtanov)\
**Post date:** [February 7, 2025, 4:42pm UTC](https://community.fibery.io/t/whats-the-optimal-way-to-use-typescript/8233/4 "2025-02-07T16:42:41Z")

</div>

Hello.  
To show auto-suggestion in automation code editor, we have defined type definitions for apis, exposed in code editor.  
Like  
`updateEntity(type: string, id: string, values: object): Promise<object>;`

We indeed use typescript when developing Fibery.  
Our internal type definitions for Fibery Entity looks like this at the moment:

`export type Entity = {"fibery/id": string; "fibery/public-id": string} & Record<string, unknown>;`

So nothing fancy, just a Record with unknown values. As Fibery has a dynamic schema, we can’t generate typescript types on compile time. We always use Schema object to iterate over FiberyEntity’s fields in our codebase (like to show fields on entity view, etc.)
