我最新的打字稿项目分为不同的模块和子模块。
我的文件结构:
package.json
(...)
/src
| /module1
| | index.ts
| | (...)
| | /subModule1
| | | index.ts
| | | (...)
| | /subModule2
| | index.ts
| | (...)
| /module2
| index.ts
| (...)
Run Code Online (Sandbox Code Playgroud)
每个(子)模块都有一个index.ts保存模块导出的文件。
现在我终于想发布我的包了。人们应该能够通过以下方式从模块导入内容:
package.json
(...)
/src
| /module1
| | index.ts
| | (...)
| | /subModule1
| | | index.ts
| | | (...)
| | /subModule2
| | index.ts
| | (...)
| /module2
| index.ts …Run Code Online (Sandbox Code Playgroud) 假设您有以下代码:
class Superclass<T>{
combine(object: Superclass<T>) {
console.log("combined!");
return object;
}
}
class Generic1 {
x = 12;
// some class...
}
class Generic2 {
y = "Hello!";
// some class...
}
new Superclass<Generic1>().combine(new Superclass<Generic2>());
Run Code Online (Sandbox Code Playgroud)
你肯定会注意到,这里应该有一个错误。Superclass<Generic1>只能与 结合Superclass<Generic1>,但决不能与 结合Superclass<Generic2>。Visual Studio 代码也显示:
但是编译后没有错误!为什么?我误解了泛型吗?
我试图抓住Java(fx)中的鼠标/键事件,即使应用程序窗口没有聚焦 ......我正在创建类似于screenrecorder的东西,我想按下像"F9"这样的键来停止录制"所以我需要检测一下这个事件.这可能吗?有没有像我可以使用的系统监听器?
〜亨利
我尝试在 LibGDX(Java) 中更改单个精灵的颜色。例如,我想更改显示蓝色工作表的 .png 的颜色。像这样:
Sprite sprite = new Sprite(new Texture("blue_sheet.png");
sprite.setColor(Color.RED);
Run Code Online (Sandbox Code Playgroud)
还有就是方法sprite.setColor(颜色色调),但它确实没有什么:(如果我用SpriteBatch.setColor(Color.RED),它会正常工作,但在逻辑将应用于所有精灵的颜色,我鸵鸟政策想给存档这个。
我的例子是以下代码:
type SomeType = {
name: string,
age: number,
} | {
xy: [number, number]
}
function someFunction(arg: SomeType) {
if (arg.name && arg.age) {
// DO STH
} else if (arg.xy) {
// DO STH
}
}
Run Code Online (Sandbox Code Playgroud)
为什么打字稿会向我显示以下错误消息?
typescript ×3
java ×2
events ×1
generics ×1
javafx ×1
libgdx ×1
listeners ×1
node-modules ×1
npm ×1
npm-publish ×1
package.json ×1
system ×1
typeguards ×1