小编Mar*_*iem的帖子

学习TypeScript - 转换类型

我是TypeScript的新手,我正在玩各种语言功能.下面是我在许多在线课程中一直在研究的代码示例.

我有问题获得继承和重载以正常工作.在整个代码中,我使用了一辆基本型Auto汽车,以及一辆儿童级卡车.

我试图看看是否有可能将汽车作为卡车投入并访问专门的功能HonkHorn.此外,我正在尝试将卡车投回到Auto并访问WriteDetails的基本功能.

在这两种情况下,似乎对象都保持原始类型.所以typecast4.HonkHorn(); 生成运行时错误:未捕获TypeError:typecast4.HonkHorn不是函数.

尝试将Truck转换为Auto将始终导致调用WriteDetails的专用覆盖.转换代码一直位于示例的底部.

有人可以帮我理解为什么会这样吗?

提前致谢!

// defines the structure of auto options
interface IAutoOptions{
    engine: Engine,
    color: string,
    price: number,
    year: number
}

// extends autooptions with truck specific options
interface ITruckOptions extends IAutoOptions{
    fourbyfour: boolean,
    bedlength: string
}

// defines the structure of engines
interface IEngine {
    enginetype: string;
    horsepower: number;
    hydraulicpump?: string
    start(warmuptime: number, callback: () => void): void;
    stop(): void;
}

// the engine class must implement the members as specified in the IEngine …
Run Code Online (Sandbox Code Playgroud)

inheritance typescript

11
推荐指数
1
解决办法
1万
查看次数

Webpack 文件加载器 publicPath

我有一个 React 项目,其中使用 webpack 3.10.0 和文件加载器 1.1.6 将一些图像和 json 文件移动到我的分发文件夹中。

\n\n

Webpack 按预期发出文件,但 React 收到我的 json 和图像资源的错误 url

\n\n

我的标记看起来像:

\n\n
<img src="../images/helloworld_a49183cf48e4a0f12aa2124fe2ed9d3a.png" \nalt="Hello World!!">\n
Run Code Online (Sandbox Code Playgroud)\n\n

但应该是:

\n\n
<img src="/assets/images/helloworld_a49183cf48e4a0f12aa2124fe2ed9d3a.png" \nalt="Hello World!!">\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的文件夹结构如下所示:\n\nC:.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80dist\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80assets\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80css\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80data\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80images\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80js\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80src\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80css\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80data\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80images\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80js\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80actions\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80components\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80containers\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80reducers\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80tests\n

\n\n

我认为文件加载器 publicPath 应该解决这个问题,但看来我要么误解了,要么我的配置有问题。\n有好心人可以帮帮我吗?

\n\n

webpack.config.js

\n\n
var path = require(\'path\');\nconst ExtractCSS = require("extract-text-webpack-plugin");\n\nmodule.exports = {\n  entry: [\n    \'./src/js/index.js\'\n  ],\n  output: {\n    path: path.resolve(__dirname, \'dist/assets/js\'),\n    filename: \'bundle.js\'\n  },\n  module: {\n    rules: [\n …
Run Code Online (Sandbox Code Playgroud)

reactjs webpack webpack-file-loader

5
推荐指数
1
解决办法
2万
查看次数