我有以下带有 Typescript项目的Node.js,它运行得非常好。但是,在调试会话期间,我注意到从另一个 Typescript 文件导出的常量总是undefined:
我有点怀疑这是由于names生成的源映射中的空数组:
{
"version": 3,
"file": "main.js",
"sourceRoot": "",
"sources": [
"../src/main.ts"
],
"names": [], // <---- empty
"mappings": ...details omitted...
}
Run Code Online (Sandbox Code Playgroud)
有没有办法从 Typescript 编译器或其他解决方案中生成正确的源映射来解决这个调试问题?以下是我的tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"target": "es2017",
"noImplicitAny": true,
"moduleResolution": "node",
"importHelpers": true,
"sourceMap": true,
"allowJs": true,
"outDir": "dist",
"baseUrl": ".",
"typeRoots": [
"./node_modules/@types"
],
"types": [
"node"
],
"paths": {
"*": [
"node_modules/*" …Run Code Online (Sandbox Code Playgroud) 根据我的理解,Kotlin中的匿名函数允许您指定返回类型。除此之外,anonymous内部的return语句将仅退出功能块,而在lambda中,它将退出封闭功能。
不过,我无法想象lambda语法无法提供的Kotlin匿名函数在现实世界中的用例是什么?
我在Postgre中有下表:
CREATE TABLE user_attempts
(
id INT PRIMARY KEY NOT NULL,
username VARCHAR(50) NOT NULL,
attempts SMALLINT NOT NULL,
lastmodified TIMESTAMP,
FOREIGN KEY ( username ) REFERENCES users ( username )
);
Run Code Online (Sandbox Code Playgroud)
我想lastmodified通过QueryDSL和Spring Data JDBC Extension 更新该字段,如下所示:
template.update(userAttempts, update -> update
.set(userAttempts.attempts, (short) 0)
.set(userAttempts.lastmodified, null) // compilation error here
.where(userAttempts.username.eq(username))
.execute();
Run Code Online (Sandbox Code Playgroud)
但是,似乎QueryDSL的set方法无法接受,null因为它将匹配多个函数签名.
我对operatorKotlin 中修饰符的使用有点困惑.例如,Kotlin operator在解构声明和属性委托期间使用修饰符,恕我直言(原谅我的无知),有点混乱,因为两个场景都在运算符重载之外.
解构:
operator fun <K, V> Map<K, V>.iterator(): Iterator<Map.Entry<K, V>> = entrySet().iterator()
operator fun <K, V> Map.Entry<K, V>.component1() = getKey()
operator fun <K, V> Map.Entry<K, V>.component2() = getValue()
for ((key, value) in map) {
// ...
}
Run Code Online (Sandbox Code Playgroud)
物业代表团:
interface ReadOnlyProperty<in R, out T> {
operator fun getValue(thisRef: R, property: KProperty<*>): T
}
interface ReadWriteProperty<in R, T> {
operator fun getValue(thisRef: R, property: KProperty<*>): T
operator fun setValue(thisRef: R, property: KProperty<*>, value: T)
}
Run Code Online (Sandbox Code Playgroud)