Trying out TypeScript for a React project and I'm stuck on this error:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ train_1: boolean; train_2: boolean; train_3: boolean; train_4: boolean; }'.
No index signature with a parameter of type 'string' was found on type '{ train_1: boolean; train_2: boolean; train_3: boolean; train_4: boolean; }'
Run Code Online (Sandbox Code Playgroud)
Which appears when I try to filter the array in my component
.filter(({ name }) => plotOptions[name]); …Run Code Online (Sandbox Code Playgroud) 我目前正在创建一个使用React创建界面的Electron应用程序。为了获得fs,我一直在使用:
const fs = window.require('fs');
Run Code Online (Sandbox Code Playgroud)
在电子窗口中工作正常。
问题是,当我为使用window.require('fs')的任何组件编写开玩笑的测试时,在运行测试时出现以下错误。
TypeError: window.require is not a function
Run Code Online (Sandbox Code Playgroud)
我浏览了有关Jest的文档,似乎解决方案是使用手动模拟生成窗口模拟(请参阅https://jestjs.io/docs/zh/manual上的 “ JSDOM中未实现的模拟方法”)-嘲笑)。但是,当我尝试模拟window.require时,请在测试文件的顶部添加
window.require = jest.fn();
Run Code Online (Sandbox Code Playgroud)
我仍然得到相同的TypeError。
我对创建Jest模拟游戏非常陌生,因此对此提供的任何帮助将不胜感激。
我当前的测试文件(Component.test.js)看起来像
window.require = jest.fn();
import React from 'react';
import renderer from 'react-test-renderer';
import Component from '../index';
describe('Testing', () => {
it('Component renders correctly', () => {
const component = renderer.create(<Component />);
let tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试配置 Docker 映像,以便用户可以输入“docker run image”并弹出一个窗口来选择输入文件。我在创建 Docker 映像时尝试使用 Tkinter,但是在尝试加载 Tkinter 时 Python 脚本出错。
由于 Tkinter 不起作用,我尝试使用以下方法切换到普通输入查询:
path= input('Input the file path:\n')
Run Code Online (Sandbox Code Playgroud)
但是现在当它到达 input() 行时,我收到“EOFError: EOF when reading a line”。
我的 Dockerfile 如下
FROM python:3
ADD script.py /
RUN pip install xlrd
RUN pip install numpy
RUN pip install matplotlib
CMD [ "python", "./script.py" ]
Run Code Online (Sandbox Code Playgroud)
关于为什么会发生这种情况的任何想法?我对使用 Docker 很陌生,因此非常感谢任何帮助:)
我正在尝试使用 pandas.read_excel 读取 .xls 文件。它在我的大多数 .xls 文件上都成功了,但对于某些文件,它会出错并显示以下错误消息:
Unsupported format, or corrupt file: Expected BOF record; found '\x00\x05\x16\x07\x00\x02\x00\x00'
Run Code Online (Sandbox Code Playgroud)
我一直在努力研究为什么这会发生在一些文件上,但不是所有文件。xlrd 版本是 1.0.0。我尝试使用 xlrd.open_workbook 手动读入,但得到了相同的结果。
有谁知道这个BOF记录指的是什么文件类型?
试图弄清楚如何在 Hangouts Chat 中将 webhook 消息发布到聊天室中的现有线程。
当我发布到 webhook URL 时,我收到以下响应:
{
"name": "spaces/123123123123/messages/128391203812903809128",
"sender": {
"name": "users/u4i3u4oi32u5oi23u4o23",
"displayName": "Mecha",
"avatarUrl": "",
"email": "",
"type": "BOT"
},
"text": "",
"cards": [
{
"header": {
"title": "Some Title",
"subtitle": "Some Subtitle",
"imageStyle": "IMAGE",
"imageUrl": "Some Image URL",
"imageAltText": ""
},
"sections": [],
"cardActions": [],
"name": ""
}
],
"previewText": "",
"annotations": [],
"thread": {
"name": "spaces/123123123123/messages/128391203812903809128"
},
"space": {
"name": "spaces/123123123123",
"type": "ROOM",
"displayName": "Chat Room"
},
"fallbackText": "",
"argumentText": "",
"createTime": …Run Code Online (Sandbox Code Playgroud)