TypeScript Tricks

· 48 words · 1 min

null!

import { useRef } from 'react';

const ref = useRef<HTMLElement>(null!);

const element = ref.current; // ref.current is HTMLElement

T[number]

const fruits = ['apple', 'orange', 'banana'] as cosnt;

type FruitsType = typeof fruits;

type Fruit = FruitsType[number]; // 'apple' | 'orange' | 'banana'

More explanation from this thread on X.


To be continued…

TypeScript