我正在尝试从使用 webpack 和 babel 编译的打字稿项目中使用https://github.com/timmywil/panzoom。
问题是打字稿方法调用:
import Panzoom from '@panzoom/panzoom';
Panzoom(document.querySelector("#pic"));
Run Code Online (Sandbox Code Playgroud)
被转换为以下 javascript:
panzoom_1.default(document.querySelector("#pic"));
Run Code Online (Sandbox Code Playgroud)
然后生成以下运行时错误:
Uncaught TypeError: panzoom_1.default is not a function
Run Code Online (Sandbox Code Playgroud)
如果我调试 javascript 则panzoom_1具有预期的函数签名并且它没有default成员。
这是无数不同类型的模块、默认导出以及 babel 和 typescript 导入方式的差异之间的某种类型的问题,但我完全迷失了。根据文档,panzoom如果有帮助,是一个 UMD 模块。
我找到了一种解决方法,可以以不同的方式导入,然后将其转换为任何方式,但这显然很疯狂,对吗?:
Uncaught TypeError: panzoom_1.default is not a function
Run Code Online (Sandbox Code Playgroud)
下面是项目配置:
import * as Panzoom from '@panzoom/panzoom';
(<any>Panzoom)(document.querySelector("#pic"));
Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<img src="pic.jpg" id="pic" />
</body>
<script src="dist/bundle.js" type = "text/javascript"></script>
</html>
Run Code Online (Sandbox Code Playgroud)
{
"compilerOptions": …Run Code Online (Sandbox Code Playgroud) Karma将捕获写入console.log但不写入任何内容的任何消息console.error.我知道业力使用了引擎盖下的log4js.
有没有办法配置业力捕获console.error?
我将模块引入到现有的打字稿项目中,以便它可以使用外部模块。当前代码扩展了字符串等基本类型,无需模块即可正常工作。一旦我引入导入,编译就会失败。
内部模块失败:
/// <reference path='../defs/react.d.ts' />
import React = require("react");
module ExampleModule {
interface String {
StartsWith: (str : string) => boolean;
}
if (typeof String.prototype.StartsWith !== 'function') {
String.prototype.StartsWith = function(str) {
return this.slice(0, str.length) === str;
};
}
export function foo() { return "sdf".StartsWith("s"); }
}
Run Code Online (Sandbox Code Playgroud)
外部模块失败:
/// <reference path='../defs/react.d.ts' />
import React = require("react");
interface String {
StartsWith: (str : string) => boolean;
}
if (typeof String.prototype.StartsWith !== 'function') {
String.prototype.StartsWith = function(str) {
return this.slice(0, str.length) …Run Code Online (Sandbox Code Playgroud) 我正在使用调试版本并在同一台机器上获得不同的结果,无论我是否在调试器下运行.我使用优秀的TestDriven.Net来运行单元测试.
代码是
我没有追溯到第一个区别(没有调试器就很棘手!)但考虑到代码是如何迭代的,它的输入敏感性和最小的差异将在给定足够时间的情况下增长到相当大的比例.
我知道fp重现性在编译器,平台和体系结构之间是多么脆弱,但是很失望地发现调试器是解决这个问题的因素之一.
我是否必须接受这个作为生活中的事实,或者您可以提供任何建议吗?
c# debugging floating-point testdriven.net visual-studio-2012
我希望localeCompare用于严格排序字符串,但我发现0当给出两个不同的 unicode 字符时它会返回,这错误地表明它们是相同的,例如
? U+211C (alt-08476) 大写字母 R = 实部
? U+211D (alt-08477) DOUBLE-STRUCK CAPITAL R = 实数集
"?".localeCompare("?", "en")
> 0
"?" === "?"
> false
"?".charCodeAt(0)
> 8476
"?".charCodeAt(0)
> 8477
Run Code Online (Sandbox Code Playgroud)
我已经查看了文档,但默认值已经用于“排序”和“变体”,它们似乎是最严格的可用:
是localeCompare不能给一个严格的排序?
netcoreapp我在构建代码时遇到错误,netstandard无法解决。
以下代码编译为netcoreapp2.2:
using System;
using System.Linq;
using System.Text.RegularExpressions;
namespace TestNamespace
{
public class TestClass
{
public static Group Example(string str, string pattern) =>
Regex.Match(str, pattern).Groups.First();
}
}
Run Code Online (Sandbox Code Playgroud)
但如果我将其更改为netstandard2.0则.First无法编译:
Class1.cs(10, 46): [CS1061] 'GroupCollection' does not contain a definition for 'First' and no accessible extension method 'First' accepting a first argument of type 'GroupCollection' could be found (are you missing a using directive or an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
但是,如果我在 Jetbrains Rider 中使用“转到代码”,则反汇编会GroupCollection解析为 …
我正在考虑替换代码如下:
foreach (var meshCut in meshCuts0)
{
ComputePolygons(meshCut, polygons);
}
foreach (var meshCut in meshCuts1)
{
ComputePolygons(meshCut, polygons);
}
Run Code Online (Sandbox Code Playgroud)
linq看起来像这样:
meshCuts0.Concat(meshCuts1).ForEach(m => ComputePolygons(m, polygons));
Run Code Online (Sandbox Code Playgroud)
我不知道linq是如何实现的,所以我不确定性能后果.我很感激一些帮助.
1)
Concat会创建一个列表副本,还是只是一个枚举器做这样的事情:
public static IEnumerable<T> Concat<T>(IEnumerable<T> a, IEnumerable<T> b)
{
foreach (var t in a)
{
yield return t;
}
foreach (var t in b)
{
yield return t;
}
}
Run Code Online (Sandbox Code Playgroud)
2)
这在Mono上是否会出现同样的行为?
3)
是否有任何参考解释如何实现linq api功能以提高性能?
谢谢!
编辑
好的,没有ForEach,所以我假设我也定义了这样的东西:
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
{
foreach(T item in source)
action(item);
}
Run Code Online (Sandbox Code Playgroud)
真正的问题是Concat是否会成为一个代价高昂的开销只是为了减少代码,感谢评论,我现在明白它不是. …
c# ×3
javascript ×3
typescript ×2
.net-core ×1
babeljs ×1
debugging ×1
karma-runner ×1
linq ×1
module ×1
string ×1
unit-testing ×1
webpack ×1