代码:
const f: any = function(...args: any[]) {
const a = this;
};
错误:
semantic error TS2683 'this' implicitly has type 'any' because it does not have a type annotation.
我正在尝试创建具有两个属性和一个方法的对象,这些方法根据选定的属性一或属性二进行一些计算。 差不多完成了,但是我得到了错误'offset' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.。 我遗漏了什么?作为一个初学者,你能给我解释一下吗? const offset = { // 'offset' implicitly has
我这里有一个伪古典类:
function Car(numWindows: number) {
this.numWindows = numWindows;
}
我想知道如何键入属性this.numWindows,因为我收到了错误消息'this' implicitly has type 'any' because it does not have a type annotation.ts(2683)。我希望在不使用ES6类的情况下对这个示例执行此操作。另外,当尝试用new关键字实例化Car时,我得到以下内容:
'new' expression,
为什么类型推断适用于这种情况?
const test = {
value: 42,
fn: () => test
};
const value = test.fn().fn().value; // typeof value is number
但对这个案子来说不是
class Test {
constructor(public readonly value: number, public readonly fn: () => Test) {}
}
const test2 = new Test(42, () => test2); // error: 't
我在js中使用了schema.virtual属性,但现在我想将它与类型记录和获取错误一起使用。这是我的密码
UserSchema.virtual('fullname').get(function () {
return `${this.firstName} ${this.lastName}`
});
我正面临着这个错误
this' implicitly has type 'any' because it does not have a type annotation.
在将大量文件转换为类型记录时,我有许多类是这样声明的。
function FooClass() {
this.bar = 1; // error TS2683: 'this' implicitly has type 'any'
// because it does not have a type annotation.
}
FooClass.prototype.myMethod = function() {
// ...
}
如何在打开严格类型检查的同时避免使用类语法重写它呢?
当我在strict文件中设置tsconfig模式时,我得到了与装饰器中的this类型相关的问题,例如我看到的提示:
TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
Infer 'this' type of 'SyncTimer' from usage
在这里,它是如何解决的-这很奇怪
如何在strict模式下正确地解决这一问题?
如果我在我的目录中键入tsc,我会得到以下错误消息:
src/temp.ts:3:24 - error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
但是,如果我在完全相同的目录中输入tsc src/temp.ts而不更改代码,我的TypeScript就会编译。
为什么这两个命令会有区别?
我以前从未遇到过这个问题..。但现在给了我..。
// TS7022: 'rootReducer' implicitly has type 'any' because it does not
// have a type annotation and is referenced directly or indirectly in its own initializer
const rootReducer = combineReducers({
employee: employee.reducer,
company: company.redu
当我试图在我的文件中导入一个组件时,我得到了这个错误:
TS7022: 'default' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
Version: typescript 4.2.2, eslint 7.32.0
这是我的脚本标签:
<script lang="ts">
import { defineCompo
export const rootReducer = combineReducers({
login: loginReducer,
});
这很好用,但只要我尝试组合另一个减速器,
export const rootReducer = combineReducers({
login: loginReducer,
logout: logoutReducer
});
我开始在rootReducer上收到一个错误
'rootReducer' implicitly has type 'any' because it does not have a
我试图在类型记录中进行递归搜索,但由于某种原因,TS无法推断函数的返回类型。
function findDirectory(
directoryId: Key,
directory: Directory,
) {
if (!directory) return;
if (directory.id === directoryId) return directory;
for (const child of directory.children) {
const res = findDirectory(directoryId, child);
if (res)
我有一个组件,当函数被调用并收到来自服务器的响应时,我想重定向到另一个路由。我在用钩子。
问题是我有一个TS错误Type error: 'this' implicitly has type 'any' because it does not have a type annotation. TS2683。
在我的tsconfig中,我试图放置"noImplicitAny": false,但它似乎不起作用。
在这种情况下有办法解决吗?
export const SignupForm = () => {
const name:any =
我有一些使用经典JS类的旧代码,我想输入检查。例如:
/**
* @constructor
*/
function Test() {
this.x = 1;
}
然而,当我运行tsc --noImplicitThis --noEmit --allowJs --checkJs test.js来检查它时,我得到了以下错误:
test.js:5:5 - error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
5 this.
我试图理解在导出函数中访问/传递'this‘时遇到的以下错误,我有以下代码:
export async function main() {
try {
console.log(this)
catch (e: any) {
}
在试图编译时给出了这个错误:
src/main.ts:55:32 - error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
55 console.log( this);
那么,有谁知道为什么我在使用猫鼬钩子和引用this时可能会得到一个类型记录错误。我不使用箭头函数,而且我知道其中的词法作用域问题,但即使使用这样的匿名函数:
UserSchema.pre("save", function(next) {
console.log(this.password);
next();
});
准确的错误信息是
'this' implicitly has type 'any' because it does not have a type annotation.
有人知道怎么绕过这件事吗?
顺便说一下,我使用
我在尝试找出以下问题的解决方案时遇到了麻烦 interface IName {
name:string;
}
let obj1:IName = {
name: "LINUS"
}
function profileInfo (age:number,location:string):string{
return `${this.name} is ${age} years old and is from ${location}` // << Error here as 'this' implicitly has type '
我正在尝试将类型记录整合到我的学习路径中,并理解与javascript的不同之处。
到目前为止,我能够解决所有的问题,但我被困在一些似乎相当基本的事情上。
function Person() {
// ERROR: this implicitly has type any because it does not have a type annotation
this.name = 'brad';
}
// ERROR: new expression, whose target lacks a construct signature, implicitly ha
类型记录似乎能够推断递归函数的类型:
/**
* Typescript correctly infers the type is
*
* const referencesSelf: () => ...
*
* Where the ellipsis means recursion of the function
*/
const referencesSelf = () => {
return referencesSelf;
};
但是,无法推断具有递归性质的类:
class ReferencesSelf {
_self: () => ReferencesSe
我第一次写Vue (3.2.13),我用的是打字本。
我收到警告了。'this' implicitly has type 'any' because it does not have a type annotation.ts(2683)
在基于react的环境中,我所做的只是(this as any),它似乎可以工作,但是这里没有。
<template>
<component :is="this.$route.meta.layout || 'div'">
<router-view />
我试图找出为什么打字稿不喜欢下面的结构。编译器错误在代码中的注释中。
const BAR = Symbol();
function foo<T>(that: T) {
if (that !== null && typeof that === "object" && BAR in that) {
// Element implicitly has an 'any' type because expression of type 'unique symbol' can't be use
我在Typescript类方法声明中有一个错误,但是我不明白这个错误消息是如何与bug联系在一起的。
消息似乎是说'this‘是any类型,但我们是在一个类定义中,所以我认为'this’真的很清楚。
有没有人能解释一下错误消息与bug的关系?
原始方法:
calcSize = function() {
return this.width * this.length; // Error on this line
};
// Error text: 'this' implicitly has type 'any' because it do
我按照这个链接启动一个示例节点js项目,使用webworker线程。
这是我的ts代码:
var Worker = require('webworker-threads').Worker;
// var w = new Worker('worker.js'); // Standard API
// You may also pass in a function:
var worker = new Worker(function(){
postMessage("I'm working before postMessage('ali
我想从字典“数据”中删除"__typename“的所有出现。我使用了堆栈溢出帖子中的一个函数:,它输出正确的答案,但我的编译器显示。我对打字很陌生,很难找到解决办法。
代码片段
import * as R from ramda;
// Dictionary "data"
const data = {
"subscription": {
"id": "10",
"subscribers": [
{
"i
我一直在遵循官方教程关于使用redux和类型记录。
所有操作都很好,除非我需要在mapState中指定传入的道具类型为mapState。
这是我从类型记录中出现的类型错误,我假设这是一个循环引用:
'connector' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
下面是教程中的代码,除了将props: Props添加到mapState之外
这不管用
interface String {
contains(s:string):boolean;
}
String.prototype.contains=(s:string):boolean=>this.indexOf(s)!==-1;
因为Property 'contains' does not exist on type 'String'
这有点令人惊讶,因为添加它是接口声明的全部要点。建议上述代码是合法的。据我所知,String在全局命名空间中,我可以通过查看lib.es2015.wellknown.d.ts来判断。
做这件事的正确方法
我是TypeScript的新手。我正在将相当复杂的Redux切片从JS转换到TS。在我所有的减速器中,我都得到了相同错误的排列。错误是TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'WritableDraft...,我将包含还原器片的完整源代码,并附带注释,以指示错误在我的IDE中显示的位置。有人能指出我的正确方向,因为我可以补救吗?提前感谢!
export type Task =
在类型记录和Vue (v2.x)中是否有方法导入引用this的函数?
我在mixins方面还没有什么进展,我很好奇这里是否有一种简单的方法。
例如:
getPath.ts
export default getPath(): string {
return this.$route.path; // 'this' implicitly has type 'any' because it does not have a type annotation.ts(2683)
}
App.vue
import getPath from "./getPath
我正在使用Cucumber-js和Typescript。 我想为我的测试创建并初始化一个驱动程序。我希望这个驱动程序在异步作用域中初始化,这样在设置它之前不会开始测试(这可能需要10秒),并且一旦它初始化,我就不必为每个场景再次进行测试。我试图将驱动程序存储在自定义的World类中,并仅在BeforeAll函数中初始化它一次,但我无法在此函数中访问this: class Context implements World {
public driver: Driver
public constructor() {
this.driver = new Driver()
}
我正在将在Dart中工作的递归函数转换为TypeScript,用于一个角度项目。令人反感的是
return this.reduceNumber(firstNameNumberReduced);
错误信息是
'reduceNumber' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
完整的功能是
r
我如何在打字稿中做这样简单的事情呢?
const [text, setText] = useState("");
我犯了很多错误,我不知道怎么改正。
Parameter 'text' implicitly has an 'any' type.ts(7006)
Parameter 'setText' implicitly has an 'any' type.ts(7006)
'useState', which lacks return-type annotation, implicitly has a
我在查看MDN关于Object.create()的文档,以了解它是如何工作的,同时查看一些人的代码。但我现在想知道的是,作为一个打字稿的新手。
我怎样才能让他们的例子在不使用类的情况下使用类型记录呢?
在ts文件中,如果不使用js类,就无法找到解决此错误的方法:'this' implicitly has type 'any' because it does not have a type annotation.
编辑:
如果我做了这样的事,我就会走得很近:
function Shape(this: any) {
this.x = 0;
this.y =
我正在尝试编写一个简单的方法装饰器,它在调用原始方法之前执行一些简单的逻辑操作。我可以找到的所有示例都归结为在结束时调用originalMethod.apply(this, args) --但是在tsconfig.json中启用了noImplicitThis,我得到了以下错误:
[eval].ts(1,224): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
我试图通过调用originalMethod.apply(this as
我试图让编译后的TypeScript代码(.tsx -> .js)与Webpack一起打包,这样我就可以做一些前端工作,并在浏览器中运行代码。(实际上,我还有更多的要求,比如需要与TypeScript服务器共享一些前端(浏览器) Node.js代码,并在电子内部运行所有这些东西,但这些都是次要的。)
我刚学习了这个教程:
当我在最后输入webpack时,我得到了1000+错误(截断):
$ webpack
[at-loader] Using typescript@2.1.4 from typescript and "tsconfig.json" from