[Canonical page](<https://docs.dhtmlx.com/planning-engine/js/api/types/link-data/>)
[Full documentation index](<https://docs.dhtmlx.com/planning-engine/llms.txt>)


# LinkData

A dependency between two tasks: which task drives which, through which pair of dates, and with how much lag. Input only: pass it in [`ProjectData.links`](<https://docs.dhtmlx.com/planning-engine/js/api/types/project-data.md>), or add and edit links through a [`SchedulingChanges`](<https://docs.dhtmlx.com/planning-engine/js/api/types/scheduling-changes.md>) change set. No call returns it.

## Fields

| Field | Type | Default | Description |
|---|---|---|---|
| `id` | `Id` | required | Link id. Must be unique among the links of the project. |
| `source` | `Id` | required | The predecessor task. |
| `target` | `Id` | required | The successor task. |
| `type` | `"fs" \| "ss" \| "ff" \| "sf" \| 0 \| 1 \| 2 \| 3 \| "0" \| "1" \| "2" \| "3"` | `"fs"` | Which date of `source` drives which date of `target`: `"fs"` finish-to-start, `"ss"` start-to-start, `"ff"` finish-to-finish, `"sf"` start-to-finish. The numbers `0`-`3` and the strings `"0"`-`"3"` are aliases, in that order. Letter codes are case-insensitive. `null` reads as `"fs"`. |
| `lag` | `number \| null` | `0` | Offset between the two dates, in working time on the target task's calendar, measured in `lag_unit`. A negative value is a lead. `null` reads as `0`. |
| `lag_unit` | [`TimeUnit`](<https://docs.dhtmlx.com/planning-engine/js/api/types/common.md#timeunit>)` \| null` | `config.duration_unit` | Unit of `lag`: `"minute"`, `"hour"` or `"day"`. `null` reads as omitted. |

`Id` is a string or a number; `0` and `"0"` name the same task. See [`Id`](<https://docs.dhtmlx.com/planning-engine/js/api/types/common.md#id>).

Unknown fields on a link are ignored.

## Validation

- A duplicate `id` throws [`InputError`](<https://docs.dhtmlx.com/planning-engine/js/api/types/errors.md>) with `kind: "validation"` and a path like `links[3].id`.
- A `type` outside the accepted values throws `InputError` with `kind: "validation"`.
- A link whose `source` or `target` is unknown or unscheduled isn't an error. The project drops it and reports a `dropped-link` note in [`ScheduleResult.notes`](<https://docs.dhtmlx.com/planning-engine/js/api/types/schedule-result.md>).
- A link between a summary and one of its own descendants is dropped the same way, unless [`SchedulingConfig.descendant_links`](<https://docs.dhtmlx.com/planning-engine/js/api/types/scheduling-config.md>) is `true`.
- A link from a task to itself is kept. It forms a one-task cycle, reported in `ScheduleResult.cycles`.

## Used by

- [`Project#solve`](<https://docs.dhtmlx.com/planning-engine/js/api/project-solve.md>), [`Project#analyze`](<https://docs.dhtmlx.com/planning-engine/js/api/project-analyze.md>) and [`schedule`](<https://docs.dhtmlx.com/planning-engine/js/api/schedule.md>): through `data.links`
- [`Project#apply`](<https://docs.dhtmlx.com/planning-engine/js/api/project-apply.md>) and [`Project#preview`](<https://docs.dhtmlx.com/planning-engine/js/api/project-preview.md>): `changes.links.add` takes `LinkData` with an optional `id` (generated when absent), and `changes.links.update` takes a partial `LinkData` with a required `id`

## Example

```js
const links = [
  { id: 1, source: 10, target: 11 },                           // finish-to-start, no lag
  { id: 2, source: 11, target: 12, type: "ss", lag: 2 },       // start 2 days after task 11 starts
  { id: 3, source: 12, target: 13, type: 2, lag: -4, lag_unit: "hour" }, // "ff", 4-hour lead
];
```

## Related

- [`ProjectData`](<https://docs.dhtmlx.com/planning-engine/js/api/types/project-data.md>) - the plan that carries `links`
- [`LinkAdd`](<https://docs.dhtmlx.com/planning-engine/js/api/types/common.md#linkadd>) - a link added through a change set
- [`LinkUpdate`](<https://docs.dhtmlx.com/planning-engine/js/api/types/common.md#linkupdate-resourceupdate-assignmentupdate>) - editing an existing link
- [Links, constraints and summaries](<https://docs.dhtmlx.com/planning-engine/js/scheduling/links-constraints-summaries.md>) - link types, lag and cycles
