小编miz*_*chi的帖子

原型如何在打字稿上扩展?

我扩展了函数原型但是typescript无法识别它.

Function.prototype.proc = function() {
  var args, target, v;
  var __slice = [].slice;
  args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
  target = this;
  while (v = args.shift()) {
    target = target(v);
  }
  return target;
};
// generated by coffee-script

var foo: (number) => (string) => number
  = (a) => (b) => a * b.length;
console.log(foo.proc("first", "second"))
Run Code Online (Sandbox Code Playgroud)

结果:tsc -e

The property 'proc' does not exist on value of type 'Function'
Run Code Online (Sandbox Code Playgroud)

我该如何扩展这个对象?

javascript typescript

18
推荐指数
2
解决办法
8409
查看次数

我可以在webpack 4中使用浏览器本机导入吗?

在某些情况下,我不想在webpack 4中使用webpack转换来动态导入.

我们可以用一些选项做到这一点吗?

async componentDidMount() {
  const { default: Greeting } = await import("/components/Greeting.js");
  this.setState({ component: Greeting });
}
Run Code Online (Sandbox Code Playgroud)

/components/Greeting.js是在服务器上预编译的.它在chrome中没有正确的webpack工作.

webpack正在尝试编译并发出错误

Uncaught (in promise) Error: Cannot find module '/components/Greeting.js'
at webpackMissingModule
Run Code Online (Sandbox Code Playgroud)

dynamic-import webpack

0
推荐指数
1
解决办法
605
查看次数

标签 统计

dynamic-import ×1

javascript ×1

typescript ×1

webpack ×1