小编Rom*_*man的帖子

类型 'Element[]' 缺少类型 'Element' 中的以下属性:type、props、key

我有带有 Typescript 和 React 环境的标准箭头映射 ES7 函数:

 const getItemList: Function = (groups: any[]): JSX.Element => 
  group.map((item: any, i: number) => {
    const itemCardElemProps = { handleEvents: () => {}, ...item}
    return <Item key={`${item.id}_${i}`} {...itemCardElemProps} />
  })
Run Code Online (Sandbox Code Playgroud)

并得到错误:

TS2739: Type 'Element[]' is missing the following properties from type 'Element': type, props, key
Run Code Online (Sandbox Code Playgroud)

版本:打字稿 3.5.3

typescript reactjs

31
推荐指数
4
解决办法
4万
查看次数

(警告)在“globals”下定义“ts-jest”配置已被弃用

我有"jest": "^29.2.1"。我的单元测试输出错误如下:

ts-jest[ts-jest-transformer] (WARN) Define `ts-jest` config under `globals` is deprecated. Please do
transform: {
    <transform_regex>: ['ts-jest', { /* ts-jest config goes here in Jest */ }],
},
ts-jest[backports] (WARN) "[jest-config].globals.ts-jest.tsConfig" is deprecated, use "[jest-config].globals.ts-jest.tsconfig" instead.
ts-jest[backports] (WARN) Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate <config-file>.
Run Code Online (Sandbox Code Playgroud)

jest.config.ts的如下:

const config = {
  roots: ['<rootDir>/src'],
  verbose: true,
  globalSetup: './globalSetup.ts',
  testEnvironmentOptions: {
    url: 'http://localhost/',
  },
  setupFilesAfterEnv: [],
  moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'], …
Run Code Online (Sandbox Code Playgroud)

unit-testing jestjs ts-jest

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

如何运行webpack-bundle-analyzer

我安装了webpack-bundle-analyzer并需要运行它.我该怎么做?我有几个错误.其中最常见的是

Could't analyze webpack bundle
Run Code Online (Sandbox Code Playgroud)

webpack webpack-dev-server webpack-2

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

chrome 禁用通知声音

我想禁用特定 URL 的通知声音。

如何禁用烦人的音效?

google-chrome

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

如何解码 google OAuth 2.0 JWT/凭证令牌?

我正在构建一个浏览器应用程序,需要使用链接中概述的 OAuth 2.0/JWT 工作流程向 Google 进行身份验证

在使用 Google OAuth 2.0 成功进行用户身份验证的情况下,Google API 会向应用程序 OAuth 发送如下响应:

{
  "clientId": "xxx...apps.googleusercontent.com",
  "credential": "yyy...123...zzz",
  "select_by": "user"
}
Run Code Online (Sandbox Code Playgroud)

我有一个 client_id 并使用 NodeJS + JS。

用户通过身份验证后,如何向应用程序提供真实的用户数据?

javascript oauth node.js oauth-2.0 google-oauth

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

cd android &amp;&amp; ./gradlew assembleRelease '.' 不是内部或外部命令、可运行的程序或批处理文件

ReactJS 官方文档建议在终端中运行以下命令来生成发布版 APK

cd android && ./gradlew assembleRelease
Run Code Online (Sandbox Code Playgroud)

响应此命令时出现异常:

cd android && ./gradlew assembleRelease '.' is not recognized as an internal or external command, operable program or batch file.
Run Code Online (Sandbox Code Playgroud)

什么是问题?

android reactjs react-native

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

错误:Minified React错误#130

我在文件./MyInput.react.js中有以下ReactJs组件

import React from 'react';

export default class MyInput extends React.Component {
  constructor(props) {
    super(props);
    this.id = getNextId();

    this.onChange = this.onChange.bind(this);
  }
  onChange(e) {
    this.props.onChange(e.target.value);
  }
  render() {
    return (
      <label htmlFor={this.id}>
        {this.props.label}      
        <input
          id={this.id}
          value={this.props.value} 
          onChange={this.onChange}
          />
      </label>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

现在我尝试将它导入./index.js,如下所示:

import {MyInput} from './MyInput.react';
Run Code Online (Sandbox Code Playgroud)

控制台返回错误:

Error: Minified React error #130
Run Code Online (Sandbox Code Playgroud)

您刚刚遇到的错误的全文是:

Element type is invalid: expected a string (for built-in components) or 
a class/function (for composite components) but got: undefined.
Run Code Online (Sandbox Code Playgroud)

这有什么问题?

ecmascript-6 reactjs es6-class

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

TS2339:类型“{}”上不存在属性“focus”。使用 React 打字稿

我有一个 JSX 类的打字稿代码

export class SearchForm extends React.PureComponent<Props, State> {

  public inputRef: React.RefObject<{}>;

  constructor(props: any) {
    super(props)
    this.inputRef = React.createRef()
  }

  public componentDidMount(): void {
      this.inputRef.current.focus()
      this.inputRef.current.select()
  ...
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试编译这段代码时,出现了一堆错误:

ERROR in ...
TS2339: Property 'className' does not exist on type '{}'.

ERROR in ...
TS2339: Property 'focus' does not exist on type '{}'.
Run Code Online (Sandbox Code Playgroud)

什么是问题?

typescript reactjs typescript-typings typescript2.0

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

Docker:运行 html 文件的基本示例 dockerfile

docker 和 dockerfile 是否有任何非常基本且仍然可行的示例来运行单个 html 文件并在 docker 的帮助下将其显示给其他人?

docker dockerfile

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

来自守护程序的错误响应:获取https://nvcr.io/v2/:未授权:需要身份验证

我开始使用NVIDIA GPU CLOUD深度学习平台.我尝试拉入控制台(命令提示符):

docker pull nvcr.io/nvidia/pytorch:17.10
Run Code Online (Sandbox Code Playgroud)

并得到消息:

Error response from daemon: Get https://nvcr.io/v2/: unauthorized: authentication required
Run Code Online (Sandbox Code Playgroud)

我的错是什么?

nvidia nvidia-docker

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

webpack-dev-server 构建和重建非常慢

我的 webpack-dev-server 工作速度非常慢。我有以下 webpack.config.js 文件:

'use strict';

var path = require('path');
var webpack = require('webpack');
var glob = require("glob");

module.exports = {
  entry: {
    wit:    [babel-polyfill',
        './index.js',
        './src/shared/styles.less']  
  },
  output: {
    path: path.resolve(__dirname, 'dist/'),
    //publicPath: '/',
    filename: 'bundle.[name].js'        
  },  
  module: {
    rules: [
      {
        test: /(\.js[\S]{0,1})$/i,
        exclude: /node_modules/,
        loaders: ['babel-loader?presets[]=env&presets[]=react&presets[]=stage-0&presets[]=stage-2']
      },
      {
        test: /\.(htm|html|xhtml|hbs|handlebars|php|ejs)$/i,
        exclude: /node_modules/,
        loader: "file?name=[name].[ext]",
      },       
      {
        test: /\.css$/i,
        exclude: [/node_modules/],
        loader: 'style-loader!css-loader'
      },     
      {
        test: /\.less$/i,
        exclude: /node_modules/,
        use: [{
          loader: "style-loader" // creates style nodes …
Run Code Online (Sandbox Code Playgroud)

webpack webpack-dev-server webpack-2

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

类型错误:(0,apollo_server_core_1.ApolloServerPluginLandingPageGraphQLPlayground)不是函数

我升级了 Nestjs 服务器包并尝试启动我的服务器。这次我得到了以下错误:

`TypeError: (0 , apollo_server_core_1.ApolloServerPluginLandingPageGraphQLPlayground) is not a function`
Run Code Online (Sandbox Code Playgroud)

我疑惑了...

apollo apollo-server

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

Jest 错误:Mongoose:看起来您正在尝试使用 Jest 的默认 jsdom 测试环境测试 Mongoose 应用程序

使用 Mongoose 中间件使用 ExpressJS 的 Jest 端点进行测试时,我遇到了以下错误:

Mongoose: looks like you're trying to test a Mongoose app with Jest's default jsdom test environment. Please make sure you read Mongoose's docs on configuring Jest to test Node.js apps: http://mongoosejs.com/docs/jest.html
Run Code Online (Sandbox Code Playgroud)

问题是什么?

mongoose express jestjs

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