Answer the question
In order to leave comments, you need to log in
How to define a type in TypeScript?
There is a difficulty in understanding types in TypeScript. It means not simple types "number, string, ...".
For example code from next.js:
class MyDocumnet extends Document {
static async getInitialProps(ctx: DocumentContext): Promise<DocumentInitialProps> {
const initialProps = await Document.getInitialProps(ctx);
return {...initialProps};
}
render(): JSX.Element {
return (
<Html lang="ru">
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
Answer the question
In order to leave comments, you need to log in
You specify the return type yourself. That is, you must know what is returned and write ts about it
by promise - functions with async return a promise by default, plus you must specify what will be returned after the promise is fulfilled. It might even be unknow if you don't know the type
from JSX.Element - the render function returns JSX.Element. Therefore, this type is indicated
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question