Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions website/docs/faq/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ exports.docs = [
title: 'How to fix "... is not a registered scale" error?',
slug: '/faq/registered-scale',
},
{
title: 'How to use react-chartjs-2 with TypeScript?',
slug: '/faq/typescript',
},
];
26 changes: 26 additions & 0 deletions website/docs/faq/typescript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
slug: /faq/typescript
---

# How to use react-chartjs-2 with TypeScript?

TypeScript has extremely robust type inference capabilities and most of the time
we can enjoy type safety and autocompletion without having to do any extra work.

But occasionally types need to be set explicitly. They can be imported from `Chart.js`:

```typescript
import type { ChartData, ChartOptions } from 'chart.js';
```

...and then used with `options` and `data` props:

```typescript
interface LineProps {
options: ChartOptions<'line'>;
data: ChartData<'line'>;
}
```

The generic type being passed is a `ChartType` that can be one of the following values:
`'bar'`, `'line'`, `'scatter'`, `'bubble'`, `'pie'`, `'doughnut'`, `'polarArea'` or `'radar'`.