相关疑难解决方法(0)

'this'隐式具有类型'any',因为它没有类型注释

当我启用noImplicitThistsconfig.json,我得到以下代码的此错误:

'this' implicitly has type 'any' because it does not have a type annotation.
Run Code Online (Sandbox Code Playgroud)
class Foo implements EventEmitter {
  on(name: string, fn: Function) { }
  emit(name: string) { }
}

const foo = new Foo();
foo.on('error', function(err: any) {
  console.log(err);
  this.emit('end');  // error: `this` implicitly has type `any`
});
Run Code Online (Sandbox Code Playgroud)

将typed添加this到回调参数会导致相同的错误:

foo.on('error', (this: Foo, err: any) => { // error: `this` implicitly has type `any`
Run Code Online (Sandbox Code Playgroud)

解决方法是替换this为对象:

foo.on('error', (err: any) => {
  console.log(err);
  foo.emit('end'); …
Run Code Online (Sandbox Code Playgroud)

typescript typescript2.0

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

打字稿:TS7006:参数'xxx'隐式具有'任意'类型

在测试我的UserRouter时,我使用的是json文件

data.json

[
  {
    "id": 1,
    "name": "Luke Cage",
    "aliases": ["Carl Lucas", "Power Man", "Mr. Bulletproof", "Hero for Hire"],
    "occupation": "bartender",
    "gender": "male",
    "height": {
      "ft": 6,
      "in": 3
    },
    "hair": "bald",
    "eyes": "brown",
    "powers": [
      "strength",
      "durability",
      "healing"
    ]
  },
  {
  ...
  }
]
Run Code Online (Sandbox Code Playgroud)

构建我的应用程序,我得到以下TS错误

ERROR in ...../UserRouter.ts
(30,27): error TS7006: Parameter 'user' implicitly has an 'any' type.
Run Code Online (Sandbox Code Playgroud)

UserRouter.ts

import {Router, Request, Response, NextFunction} from 'express';
const Users = require('../data');

export class UserRouter {
  router: Router;

  constructor() {
  ... …
Run Code Online (Sandbox Code Playgroud)

typescript

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

反应导航 5 错误绑定元素“导航”隐式具有“任何”类型.ts

我是本机反应的新手。我正在尝试使用 react-navigation 5 实现导航。我有两个屏幕主页和个人资料。这两个组件都收到了导航道具,但打字稿给了我以下错误

Binding element 'navigation' implicitly has an 'any' type.ts(7031)
Run Code Online (Sandbox Code Playgroud)

如何摆脱这个错误。

先感谢您

注意 - 我正在使用打字稿

应用程序.tsx

import 'react-native-gesture-handler';

import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';

const Stack = createStackNavigator();

import Home from './screens/home'

const App  = () => {

  const ProfileScreen = ({}) => {
    return <Text>This is Jane's profile</Text>;
  };
  
  return (
    <NavigationContainer>

    <Stack.Navigator>
        <Stack.Screen
          name="Home"
          component={Home}
          
        />
        <Stack.Screen name="Profile" component={ProfileScreen} />
      </Stack.Navigator>

  </NavigationContainer>

  );
};
Run Code Online (Sandbox Code Playgroud)

主页.tsx

import React from 'react';
import …
Run Code Online (Sandbox Code Playgroud)

javascript typescript reactjs react-native react-navigation

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