У меня есть server.ts :
Код: Выделить всё
const express = require('express');
type Message = {
author: string,
message: string
}
declare global {
namespace Express {
interface Locals {
chat: Array
}
}
}
/** Setup Express server */
const app = express();
app.use(express.json());
let sampleMessage: Message = {
author: 11
}
app.locals.resetChat = () => {
app.locals.chat = [{author: 11, message: 'Welcome to the chat!'}];
};
app.locals.resetChat();
export {};
Код: Выделить всё
server.ts:24:3 - error TS2322: Type 'number' is not assignable to type 'string'.
24 author: 11
~~~~~~
server.ts:6:3
6 author: string,
~~~~~~
The expected type comes from property 'author' which is declared here on type 'Message'
Found 1 error in server.ts:24
Подробнее здесь: https://stackoverflow.com/questions/798 ... -something
Мобильная версия