我正在 Typescript 游乐场中尝试两个实现相同接口的不同类。我不明白为什么接口中返回类型的方法不会触发错误,如果它的实现返回除 void 之外的其他内容speak()。void
我必须使用返回类型显式实现该方法void才能触发类型检查。对于 以外的返回类型似乎不会发生这种情况void,如下所示。
interface Person {
speak(): void;
walk(): number;
}
export class HumanOne implements Person {
speak() {
return 'Hello'; // No type error
}
walk() {
return 'Walking'; // Type error
}
}
export class HumanTwo implements Person {
speak(): void {
return 'Hello'; // Type error
}
walk(): number {
return 'Walking'; // Type error
}
}
Run Code Online (Sandbox Code Playgroud) 我试图将一个favicon添加到Next.js静态站点,但运气不佳。
我尝试使用https://nextjs.org/docs/#custom-document中的组件自定义文档'next/document'
直接链接到favicon.ico文件不起作用,因为该文件未包含在构建中,并且href不会更新为 /_next/static/...
导入图像并添加到链接的href也不起作用(请参见注释掉的行)。
import React from 'react';
import Document, { Html, Head, Main, NextScript } from 'next/document';
// import favicon from '../data/imageExports';
export default class MyDocument extends Document {
static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx);
return { ...initialProps };
}
render() {
return (
<Html>
<Head>
{/* <link rel="shortcut icon" href={favicon} /> */}
<link rel="shortcut icon" href="../images/icons/favicon.ico" />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
Run Code Online (Sandbox Code Playgroud)
网站链接已添加,但未显示。我希望它在导入文件时能正常工作,但是它只是添加了一个<link …