-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cc.d.ts 错误: ITweenOption 中的 target?: object
应该为 target?: any
#16937
Comments
|
如果要让 current 在函数里能够准确的推测出类型 , 我需要给 current 指定类型. 但是无论什么类型, 都会出现类似错误. |
有时候我对cocos真的是恨铁不成钢. . cocos是不是雇佣了一群根本不会ts的人在写ts啊? |
大佬批评的是,还请不吝赐教。 import { _decorator, Component, Node, Tween, tween, Vec3 } from 'cc';
import * as cc from 'cc';
const { ccclass, property } = _decorator;
class MyCustomData {
constructor (a) {
this._aaa = a;
}
_aaa = 0;
}
class TestOne {
_customData = new MyCustomData(0);
foo (): void {
const tweenDuration: number = 1.0;
tween(this._customData).to(
tweenDuration,
new MyCustomData(100),
this,
).start();
}
onUpdate (target: typeof this._customData, ratio: number): void {
console.log(`ratio: ${ratio}, aaa: ${target._aaa}`);
}
}
class TestTwo {
_node1 = new Node('node1');
_node2 = new Node('node2');
foo (): void {
this._node2.setPosition(100, 0, 0);
const tweenDuration: number = 1.0;
tween(this._node1).to(
tweenDuration,
this._node2,
this,
).start();
}
onUpdate (target: cc.Node, ratio: number): void {
console.log(`ratio: ${ratio}, ${target.name}: ${target.position.x}`);
}
}
@ccclass('MoveSprite')
export class MoveSprite extends Component {
start (): void {
new TestOne().foo();
new TestTwo().foo();
}
}
我按引擎的 eslint 配置,模拟你的写法,测试了一下。发现并没有 eslint 的报错。 |
@dumganhar 这事不归eslint管啊。是ts编译器给出的错误。 |
难道 cc.Node 不是 object 子类型吗?我在 vscode 中写这些代码,并没有你说的这个报错。所以你说有问题,就甩一句话出来,这是解决问题的方式吗? 这里 target: object 类型表示需要其类型是对象类型。你改成 target: any,你是希望传递 number?boolean?还是 null , undefined 作为 target ? |
当然不是了。js里是,ts里object是 {} 。 |
这里的 object 和 ts 的 typeof {} 是等价的 |
并不是说object 只能表示 {} |
请指出我上述的测试代码,为什么没有你说的报错。所以我让你别一句话吐槽,show me the code,ok? |
typeof 在ts里也有两种意义。 |
两位,我实测了一下,开了严格模式会报错, 没开严格模式不会报错 |
我们先明确一个事情, |
我现在为了 在onUpdate李能够获得current具体的类型信息,我需要在current后面补充声明具体的类型,比如cc.Node 。 这里有点绕。 |
以上代码 你那边不报错吗? @dumganhar 以上是我这边的错 |
开启严格模式 |
首先 我确实开启了严格模式. 其次 难道你们不是也应该开启才对吗? 你们自己开发的时候 偷偷把严格模式关了 是不是因为严格模式很烦? |
关于 tsconfig 和 eslint 的设置问题 , 很久之前我和你们的员工深入交流过 (微信上) . 可惜后来他离职了. 我也是在没有耐心把说过的话再重复一遍了. 以后有机会去厦门当面交流吧. 反正现在 cocos 的tsconfig 设置挺坑的. 你们自己开发的时候应该也觉得烦. |
说回这个issue本身, 难道官方的 d.ts 不是应该做到 严格模式 和 非严格模式都不应该出错才对吗? |
关于 tsconfig , 我顺便回复了一下 这个 #16542 里面 @dumganhar 的问题. |
Cocos Creator version
3.8.2
System information
all
Issue description
用 object 在很多时候会报错.
Relevant error log output
No response
Steps to reproduce
无
Minimal reproduction project
No response
The text was updated successfully, but these errors were encountered: