小编Ant*_*yak的帖子

typescript,错误:forEachIdentifierInEntityName,typescript.js中的"Debug Failure.False Expression":24094:26

将Typescript版本从2.8.4升级到2.9.2时出现这个奇怪的错误:

ERROR in ./js/main.ts
Module build failed (from ./node_modules/ts-loader/index.js):
Error: Debug Failure. False expression.
at forEachIdentifierInEntityName (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:24094:2
at bindPropertyAssignment (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:24044:17)
at bindStaticPropertyAssignment (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:24029:13
at bindSpecialPropertyAssignment (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:24020:1
at bindWorker (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:23669:29)
at bind (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:23560:13)
at visitNode (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:14777:24)
at Object.forEachChild (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:15021:24)
at bindEachChild (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:22352:16)
at bindChildrenWorker (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:22434:21)
at bindChildren (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:22322:17)
at bind (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:23571:21)
at C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:22328:94
at bindEach (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:22344:21)
at bindEachFunctionsFirst (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:22328:13)
at bindChildrenWorker (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:22426:21)
at bindChildren (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:22322:17)
at bindContainer (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:22270:17)
at bind (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:23574:21)
at bindSourceFile (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:21935:17)
at Object.bindSourceFile (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:21876:9)
at initializeTypeChecker (C:\devel\autostream-web\node_modules\typescript\lib\typescript.js:51156:20)
at …
Run Code Online (Sandbox Code Playgroud)

typescript

7
推荐指数
1
解决办法
1785
查看次数

javascript拦截来自web worker + file urls的http fetch

我想拦截我的应用程序中所有部分和库的提取,同时我不想破坏通过文件URL处理应用程序的可能性 - 它对电子和移动设备(通过WebView)很有用.现在,我发现了两种可行的方法:

  1. 这里的东西

    const realFetch = window.fetch;
    window.fetch = function() {
    // do something
    return realFetch.apply(this, arguments)
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 这里的东西,服务工作者注册:

main.js:

if ('serviceWorker' in navigator) {
  window.addEventListener('load', function() {
  navigator.serviceWorker.register('sw.js').then(function(registration) {
    console.log('Service worker registered with scope: ', registration.scope);
  }, function(err) {
  console.log('ServiceWorker registration failed: ', err);
});
});
}
Run Code Online (Sandbox Code Playgroud)

sw.js:

self.addEventListener('fetch', function(event) {
  event.respondWith(
  // intercept requests by handling event.request here
  );
});
Run Code Online (Sandbox Code Playgroud)

使用第一种方法,我无法拦截来自Web工作者的获取请求.第二种方法不适用于文件URL,我希望我的应用程序通过文件URL工作,因为它允许我通过Electron用于桌面或WebView for Android使用应用程序.有没有其他方法来拦截获取请求?

PS我无法修改我试图拦截请求的工人.

更新:根据@Ciro Corvino的回答,我尝试了第三种方法:在任何其他方面之前启动我自己的工作人员并尝试从那里重新定义提取.不幸的是,这对我不起作用,这里是代码:

function redefineFetch() {
console.log('inside worker');
if …
Run Code Online (Sandbox Code Playgroud)

javascript web-worker

7
推荐指数
1
解决办法
371
查看次数

Webpack,在编译期间评估某些模块

我想创建一个Webpack加载器(或插件),它允许在编译期间将对某个方法的调用替换为此方法返回的结果.例如,假设我有一个名为transpile_time.js的文件:

import {SomeUsefullStuff} from 'a_very_cool_lib';   //<-- this should be resolved correctly

module.exports = function{
   //let's assume that 'a_very_cool_lib' is used somewhere here
   return 'console.log(\'tralala\')';
}
Run Code Online (Sandbox Code Playgroud)

而且,我还有另一个名为App.ts的文件:

import {default as tt} from './transpile-time';
....
function someFunc(){
  ...
  tt();      // <------ I want this code to be replaced to 
             // 'console.log(\'tralala\')'
             // during the compilation process
}
Run Code Online (Sandbox Code Playgroud)

对于App.js,我使用了自定义加载器.在EsprimaEstraverse以及Escodegen的帮助下,我能够操纵源代码,但在某些时候我需要解决依赖关系

import {default as tt} from './transpile-time';
Run Code Online (Sandbox Code Playgroud)

动态地在我的加载器中,它也可以拥有它自己的依赖项.在上面的例子中,

import {SomeUsefullStuff} from 'a_very_cool_lib'; 
Run Code Online (Sandbox Code Playgroud)

应该正确解决.Webpack …

javascript webpack

6
推荐指数
0
解决办法
244
查看次数

玩笑+打字稿+ es6模块(再次,2019)-SyntaxError:意外的令牌导出

我仍然在尝试使用jest,typescript和es6模块时遇到问题。我的测试是用Typescript编写的,我正在尝试从使用es6模块的js文件中导入对象。为此,我遵循了jest文档,并在位于项目根目录下的babel.config.js中包含以下内容:

module.exports = {
presets: [
    [
        '@babel/preset-env',
        {
            targets: {
                node: 'current'
            }
        }
    ]
]
Run Code Online (Sandbox Code Playgroud)

};

我安装了以下依赖项:

"devDependencies": {
  "@babel/core": "^7.2.2",
  "@babel/preset-env": "^7.3.1",
  "@types/jest": "^23.3.13",
  "@types/node": "^10.12.18",
  "babel-jest": "^24.1.0",
  "jest": "^23.6.0",
  "rollup": "^1.1.2",
  "rollup-plugin-terser": "^4.0.4",
  "rollup-plugin-typescript2": "^0.19.2",
  "ts-jest": "^23.10.5",
  "ts-node": "^8.0.1",
  "typescript": "^3.2.4"
}
Run Code Online (Sandbox Code Playgroud)

在jest.config.js中,我有以下内容:

module.exports = {
verbose: true,
transform: {
    "^.+\\.jsx?$": "babel-jest",
    '^.+\\.ts?$': 'ts-jest'
},
testEnvironment: 'node',
testRegex: '/test/.*\\.(test|spec)?\\.(ts|tsx)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node']
};
Run Code Online (Sandbox Code Playgroud)

最后,我想在测试中像这样导入:

import {Dag, Directions} from "../dist/dag";
Run Code Online (Sandbox Code Playgroud)

它说:SyntaxError:意外的令牌导出 …

javascript typescript jestjs babel-jest

6
推荐指数
1
解决办法
2216
查看次数

如何绘制缩放时不改变的虚线

当我使用“line-dasharray”属性绘制虚线时,它的行为很奇怪 - 缩放时线的长度和间隙会发生变化。请参阅示例。问题:如何绘制具有恒定线和间隙长度的虚线,当放大/缩小时这些线和间隙长度不会改变?

//这个愚蠢的机器人说我的帖子主要是代码。不知道出了什么问题

//但必须添加一些愚蠢的文本行

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset='utf-8' />
    <title>Add a GeoJSON line</title>
    <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
    <script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.1/mapbox-gl.js'></script>
    <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.1/mapbox-gl.css' rel='stylesheet' />
    <style>
        body { margin:0; padding:0; }
        #map { position:absolute; top:0; bottom:0; width:100%; }
    </style>
    </head>
    <body>

    <div id='map'></div>
    <script>
    mapboxgl.accessToken = 'pk.eyJ1IjoibHVjYXN3b2oiLCJhIjoiY2l5Nmg4cWU1MDA0ejMzcDJtNHJmZzJkcyJ9.WhcEdTYQH6sSw2pm0RSP9Q';
    var map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/streets-v9',
    center: [-122.486052, 37.830348],
    zoom: 15
    });

    map.on('load', function () {

    map.addLayer({
        "id": "route",
        "type": "line",
        "source": {
            "type": "geojson",
            "data": {
                "type": "Feature", …
Run Code Online (Sandbox Code Playgroud)

mapbox mapbox-gl-js

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

Rollup + Typescript + 将图像加载为 base64

尝试使用 Rollup 预加载图像时遇到问题。所有应该起作用的废话却不起作用,不知道为什么。有人设法让它发挥作用吗?这是我在 rollup.congig.js 中的内容:

import image from 'rollup-plugin-image'
...
plugins: [
        image(),
        json(),
        resolve(),
        commonjs(),
        typescript({
            typescript: require('typescript'),
        }),
        (process.env.BUILD === 'production' ? terser() : {})
Run Code Online (Sandbox Code Playgroud)

这是我在来源中得到的内容:

import CAR_IMAGE from "../resources/expand.png";
Run Code Online (Sandbox Code Playgroud)

最后我从 rtp2 插入中收到一个错误,其中显示:

语义错误 TS 2307,找不到模块“../resources/expand.png”

奇怪的是,我在其他各种用于汇总的图像加载插件中也得到了同样的结果。路径是正确的,图像就在那里。我已经被这个错误搞疯了=((

更新:这里是可重现此错误的存储库:

https://github.com/AntonPilyak/rollup-image-bug

更新 2:产生了错误:

https://github.com/rollup/rollup-plugin-url/issues/22

https://github.com/alwaysonlinetxm/rollup-plugin-img/issues/5

https://github.com/rollup/rollup-plugin-image/issues/10

怎么可以这么蹩脚?=(((

rollup typescript rollupjs

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

How to call a derived class method?

I have the following classes:

class A:
    def __init__(self):
         #base constructor implementation
         pass

    def __virt_method(self):
        raise NotImplementedError()

    def public_method(self):
        self.__virt_method()

class B(A):
    def __init(self):
        A.__init__(self)
        #derived constructor implementation
        pass

    def __virt_method(self):
        #some usefull code here
        pass
Run Code Online (Sandbox Code Playgroud)

I'm trying to use it like this, supposing that the overridden method to be called:

b = B()
b.public_method()
Run Code Online (Sandbox Code Playgroud)

But instead I'm getting NotImplementedError (Am I doing something wrong or is it a Python (2?) problem? I know that Python 2 is deprecated and …

python python-2.7

4
推荐指数
1
解决办法
43
查看次数

Mapbox gl js-重叠的图层和鼠标事件处理

是否有任何清晰可靠的(和描述的)机制来控制Mapbox GL JS中重叠层的鼠标事件?例如,我有3个重叠的图层,但是希望仅对最上面的图层调用单击处理程序,而不是为所有3个图层调用该单击处理程序-是否可以某种方式?现在,作为一种解决方法,我跟踪MouseEnter和MouseLeave事件并基于此事件调用适当的处理程序。但是我根本不喜欢这种解决方案,因为它会用过多的逻辑破坏我的代码。

javascript mapbox mapbox-gl-js

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

Typescript(或 Javascript)Fetch API async/await 错误处理

我想使用 async/awayt 语法、Fetch API 并希望实现以下行为:

如果响应不是 200,则记录响应,不要抛出任何内容并返回 null。如果响应为 200,则返回响应。

但!Fetch API 对与 404、505 或 200 不同的所有内容抛出异常,最后我得到了一个丑陋的结构,如下所示:

...
try{
 let response = await fetch(url, {method: 'GET', mode: 'cors'});
 if(response.status != 200){
    console.log('Failed to get what I want, got status: ' + response.status);
    return null;
 }
catch(e){
  console.log('error bla bla');
  return null;
}
...
Run Code Online (Sandbox Code Playgroud)

有没有更优雅的方法来实现相同的目标?

javascript fetch

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

OSX、USB 大容量存储发现

我正在尝试在 MAC OSX 下发现 USB 大容量存储设备。我希望获得设备类别,并在此基础上决定该设备是否是大容量存储。但是,对于我拥有的所有 USB 闪存驱动器,我得到的设备类 == 0,这似乎是一个复合设备。请帮助我弄清楚我做错了什么,或者,也许还有什么其他可靠的方法来发现 USB 大容量存储设备(我需要获取 PID、VID 和安装点)。这是我的代码:

#import <iostream>
#import <IOKit/IOkitLib.h>
#import <IOKit/usb/IOUSBLib.h>
#import <IOKit/IOCFPlugIn.h>
#import <IOKit/usb/USBSpec.h>
#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
CFMutableDictionaryRef matchingDictionary = NULL;
io_iterator_t foundIterator = 0;
io_service_t usbDevice;
matchingDictionary = IOServiceMatching(kIOUSBDeviceClassName);
IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDictionary, &foundIterator);
for(usbDevice = IOIteratorNext(foundIterator); usbDevice; usbDevice = IOIteratorNext(foundIterator))
{
    IOCFPlugInInterface** plugin = NULL;
    SInt32 theScore=0;
    IOReturn err;

    err = IOCreatePlugInInterfaceForService(usbDevice, kIOUSBDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &plugin, &theScore);
    if (err!= 0){
        std::cout<<"error, error …
Run Code Online (Sandbox Code Playgroud)

c++ macos usb iokit usb-mass-storage

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

如何在 MapBox GL JS 中从 GeoJson 源绘制双线?

我在 Mapbox 中使用数据驱动样式来自定义从 GeoJson 源获取的线条样式。除了将线变成多边形或在附近绘制第二条线之外,还有什么方法可以以某种方式绘制双线吗?

mapbox mapbox-gl-js

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