# TypeScript Types

> Infinite Table types for TypeScript are published as part of the package, as named exports from the root of the package.

Canonical page: https://infinite-table.com/angular/docs/learn/getting-started/typescript-types

Our `TypeScript` types are published as part of the package, as named exports from the root of the package.

The 2 main components that you can need to use and import are:

- `InfiniteTable`
- `DataSource`

```ts
import { InfiniteTable, DataSource } from '@infinite-table/infinite-angular';
```

The Angular components are generic classes (`InfiniteTable<T>`, `DataSource<T>`): with `strictTemplates`, Angular infers the type of the data from the inputs you bind in the template. Bind the types of the values you pass as inputs - the fields of your component - to the type of the data you are rendering: that is where TypeScript checks them.

```ts
type Developer = {
  id: number;

  firstName: string;
  lastName: string;

  currency: string;
  salary: number;
};

@Component({
  selector: 'developers-grid',
  imports: [DataSource, InfiniteTable],
  template: `
    <!-- the data type of both components is inferred from the bound inputs -->
    <infinite-data-source [data]="data" primaryKey="id">
      <infinite-table [columns]="columns" />
    </infinite-data-source>
  `,
})
export class DevelopersGrid {
  protected readonly data: Developer[] = [];

  // the type of the `columns` input, bound to the type of the data
  protected readonly columns: InfiniteTablePropColumns<Developer> = {
    firstName: { field: 'firstName' },
    salary: { field: 'salary', type: 'number' },
  };
}
```

Throughout the documentation, we will use the `DATA_TYPE` placeholder to refer to the type of the data that the `InfiniteTable` and `DataSource` components are bound to.

You can still use `InfiniteTable` in plain JavaScript, but you won't get all the type-checking benefits.

Both `InfiniteTable` and `DataSource` components have types provided for most of the props they support. Generally the naming pattern is `<COMPONENT_NAME>Prop<PROP_NAME>`, so here are a few examples to clarify the rule:

```ts
import type {
  InfiniteTablePropColumns,
  // corresponding to the `columns` input
  DataSourcePropGroupBy,
  // corresponding to the `groupBy` input
} from '@infinite-table/infinite-angular';
```

## `DataSource` Types

Here are a few examples for types for the `DataSource` component:

- `DataSourcePropGroupBy<DATA_TYPE>` - the type for [DataSource.groupBy](https://infinite-table.com/angular/docs/reference/datasource-props/index.md#groupBy)

```ts
import type { DataSourcePropGroupBy } from '@infinite-table/infinite-angular';
```

- `DataSourcePropAggregationReducers<DATA_TYPE>` - the type for [DataSource.aggregationReducers](https://infinite-table.com/angular/docs/reference/datasource-props/index.md#aggregationReducers)

```ts
import type { DataSourcePropAggregationReducers } from '@infinite-table/infinite-angular';
```

Not all the `DataSource` props have types exported that follow this convention, so you can always use `DataSourceProps<DATA_TYPE>` to get the type that define all the props.

In this way you can access specific prop types by name

- `DataSourceProps<DATA_TYPE>['groupBy']` - the type for [DataSource.groupBy](https://infinite-table.com/angular/docs/reference/datasource-props/index.md#groupBy)
- `DataSourceProps<DATA_TYPE>['data']` - the type for [DataSource.data](https://infinite-table.com/angular/docs/reference/datasource-props/index.md#data)
- etc

## `InfiniteTable` Types

Below you can find a few examples for types for the `InfiniteTable` component:

- `InfiniteTablePropColumns<DATA_TYPE>` - the type for [InfiniteTable.columns](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns)

```ts
import type { InfiniteTablePropColumns } from '@infinite-table/infinite-angular';
```

- `InfiniteTablePropRowStyle<DATA_TYPE>` - the type for [InfiniteTable.rowStyle](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#rowStyle)

```ts
import type { InfiniteTablePropRowStyle } from '@infinite-table/infinite-angular';
```

- `InfiniteTablePropColumnGroups<DATA_TYPE>` - the type for [InfiniteTable.columnGroups](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columnGroups)

```ts
import type { InfiniteTablePropColumnGroups } from '@infinite-table/infinite-angular';
```

Not all the `InfiniteTable` props have types exported that follow this convention, so you can always use `InfiniteTableProps<DATA_TYPE>` to get the type that define all the props the `InfiniteTable` component supports.

In this way you can access specific prop types by name:

- `InfiniteTableProps<DATA_TYPE>['columns']` - the type for [InfiniteTable.columns](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns)
- `InfiniteTableProps<DATA_TYPE>['columnSizing']` - the type for [InfiniteTable.columnSizing](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columnSizing)
- etc

Worth mentioning is the `InfiniteTableColumn<DATA_TYPE>` prop, which defines the type for the table [`columns`](https://infinite-table.com/angular/docs/reference/infinite-table-props.md#columns).
