Recomending for (in props) children use React.ReactNode type
type MessageType = {children: React.ReactNode}
If is error, you can tell ts, that is normal situation
//@ts-expect-error
Only specified symbols
operator: '+', '-', '*', '/'
Get auto types from object
const user = {name: 'Name', isActive: true}
type User = typeof user
// type User = {name: string, isActive: boolean}
Get only keys
type UserKeys = keyof user
// type UserKeys = "name" | "isActive"
operators: keyof typeof operators
similar
type kazkas = tyopeof operators
type kazkas1 = keyof kazkas
Object of similar items
type OperationFn = (left: number, right: number) => number
const operations: Record<string, OperationFn> = {
'+': (left, right) => left + right,
'-': (left, right) => left - right,
}
Jeigu norim apriboti (kad tik šitie butu)
const operations = {
'+': (left, right) => left + right,
'-': (left, right) => left - right,
} satisfies Record<string, OperationFn>
Native html element props
function MySpan(props: React.ComponentProps<'span'>) {
return <span {...props}/>
}
Jeigo norime praplėsti savais
function MySpan(props: React.ComponentProps<'span'> & {size?: 'small' | 'medium'}) {
return <span {...props}/>
}