我有这个文件:
//foo.js
var foo = function () {
return "foo";
};
module.exports = foo;
Run Code Online (Sandbox Code Playgroud)
所以,我想将它导入我的Typescript文件.我试过这个
//typescript.ts
import * as foo from ("./foo");
Run Code Online (Sandbox Code Playgroud)
没工作.我读到了这个'环境'模块,所以我添加了这个
//typescript.ts
/// <reference path="./foo.d.ts" />
import * as foo from ("./foo");
Run Code Online (Sandbox Code Playgroud)
我在同一个文件夹中添加了一个"foo.d.ts"文件,其目的是让打字稿知道导入函数的类型:
declare module "foo"
{
function foo(): string
export = foo;
}
Run Code Online (Sandbox Code Playgroud)
没运气.
我认为问题出在导入语法上(对于es6和commonjs模块,你不能使用相同的语法,对吧?).所以我这样做了.
import foo = require("./foo");
Run Code Online (Sandbox Code Playgroud)
正如您可能猜到的那样,这也不起作用.
当我将它作为节点模块安装npm install d3并引用其d.ts文件时,我已经能够成功导入d3 .我用这段代码做了:
import * as d3 from "d3";
Run Code Online (Sandbox Code Playgroud)
我无法对任何其他模块(jquery,box2d,box2d-commonjs等)以及我自己的库(如上所示)执行相同的操作.我是Typescript的新手,所以可能我错过了一些非常明显的东西,但我自己也无法弄明白.
我知道有很多命名约定来构建应用程序(单数的名称数据库表,大写的模型和全部小写的包),但我没有找到任何建议来命名相关的元素.像"如果你命名你的网址x,那么你的视图应该命名xview"将是有用的.
我决定使用以下规则编写我的第一个Django应用程序,但我觉得我可能会打破一些DRYesque原则.我如何命名URL,模板,模型和视图有什么问题吗?
car/put car_put(); 查看名称:car_putCarcar_put.htmlcar/1获取ID为1的汽车);car_get(); 查看名称:car_getCarcar_get.htmlcar/patch/1编辑ID为1的汽车)car_patch(); 查看名称:car_patchCarcar_patch.htmlcar/delete/1删除ID为1的汽车)car_delete(); 查看名称:car_deleteCarcar_delete.html我没有构建API,可以从上面的示例中推断出的命名规则受到REST的启发,但我的目的不是构建API,只是为了更好地组织我的代码.
该文件说:"你也可以提供一个参数下一个方法发送值到发电机上." 它将它发送到哪里?
例如,拿这三个发电机:
function* one() {
while(true) {
var value = yield null;
}
}
var g1 = one(); g1.next();
g1.next(1000); //yields null
function* two() {
var i = 0;
while (true) {
i += yield i;
}
}
var g2 = two(); g2.next();
g2.next(1000) // yields 1000
function* three(){
var index = 0;
while (true)
yield index++;
}
g3 = three();
g3.next();
g3.next(1000); // yields 1
Run Code Online (Sandbox Code Playgroud)
在生成器3和1中,传递的参数对其没有影响next.这是为什么?发电机2如何计算其返回值?为什么它会受到给定参数的影响?
在 golang-migrate 的文档中,说你可以运行这个命令来运行一个文件夹中的所有迁移。
docker run -v {{ migration dir }}:/migrations --network host migrate/migrate
-path=/migrations/ -database postgres://localhost:5432/database up 2
Run Code Online (Sandbox Code Playgroud)
您将如何执行此操作以适应不鼓励使用的新 docker-compose 语法--network?
更重要的是:您将如何连接到另一个容器中的数据库,而不是连接到本地主机中运行的数据库?
我在Muenchian方法的实现中看到了这行代码:
<xsl:for-each
select="//product[count(. | key('products-by-category', @category)[1]) = 1]">
Run Code Online (Sandbox Code Playgroud)
我不知道发生了什么count().我认为这count(.)意味着count(self::product),它始终为1,并且管道运算符(|)添加了与密钥匹配的第一个节点,但是如果产品具有,那么密钥"按类别的产品"不应始终返回节点集. 'category'属性因此匹配?
这个for-each循环在哪些元素中迭代?你能为这个表达提供自然语言翻译吗?谢谢.
我试图按年份和国家分组总销售额.这按预期工作:
SELECT Year, Country, SUM([Total Sales])
FROM Table
GROUP BY Country, Year;
Run Code Online (Sandbox Code Playgroud)
然后,我必须比较每个国家对一年总销售额的贡献.我这样做了:
SELECT Year, Country, SUM([Total Sales]),
SUM([Total Sales]) OVER(PARTITION BY Year)
FROM Table
GROUP BY Country, Year;
Run Code Online (Sandbox Code Playgroud)
这给了我这个错误:
列'Table.Total Sales'在选择列表中无效,因为它不包含在聚合函数或GROUP BY子句中.
我见过人们使用NewRequest()“net/http”包的方法来测试 API。为什么不使用NewRequest()“net/http/httptesting”中的方法?有什么不同?文档建议如下:
// To generate a client HTTP request instead of a server request, see
// the NewRequest function in the net/http package.
Run Code Online (Sandbox Code Playgroud)
例如,处理 cookie 有何不同?两者似乎非常相似。
我有观察者模式的实现:
type EventHandler = <T extends Event>(event: T) => void;
interface Subscriber<T> {
event: EventEnum;
callback: EventHandler<T>;
}
Run Code Online (Sandbox Code Playgroud)
我想要这个Subscriber接口,以便我可以声明,例如:
interface EventEmitter {
Xsubscribers: Array<Subscriber<EventX>>;
Ysubscribers: Array<Subscriber<EventY>>
addEventXListener: (callback: EventHandler<EventX>) => void;
addEventYListener: (callback: EventHandler<EventY>) => void;
}
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我收到以下错误:
错误 TS2315:类型“EventHandler”不是通用的。
我想仅从点(1,1)过滤掉小于10个单位的行.我的数据框有两列,x和y.
这是我尝试过的:
filter(df, dist( rbind(c(1,2), c(x,y)) ) < 10 )
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用.它总是返回0行结果,虽然我知道它应该返回几行.我该怎么调试呢?我想在每次迭代中打印传递给x和y的每个值.
每个请求,这是dput(head(df))的输出:
structure(list(x = c(1, 2, 3, 4, 5), y = c(1, 1, 1, 1, 1)), .Names = c("x",
"y"), row.names = c(NA, 5L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud) 我去,我假设切片是通过引用传递的,但这似乎适用于值,但不适用于数组本身。例如,如果我有这个结构:
l := Line{
Points: []Point{
Point{3, 4},
},
}
Run Code Online (Sandbox Code Playgroud)
我可以定义一个变量,该变量传递对结构切片的引用
slice := l.Points
Run Code Online (Sandbox Code Playgroud)
然后如果我修改它,变量引用的原始结构将反映这些修改。
slice[0].X = 1000
fmt.Printf(
"This value %d is the same as this %d",
slice[0].X,
l.Points[0].X,
)
Run Code Online (Sandbox Code Playgroud)
这与我认为按值传递的数组的行为不同。因此,例如,如果我使用数组定义了前面的代码:
l := Line{
Points: [1]Point{
Point{3, 4},
},
}
arr := l.Points
arr[0].X = 1000
fmt.Println(arr.[0].X != s.Points[0].X) // equals true, original struct is untouched
Run Code Online (Sandbox Code Playgroud)
然后,该l结构不会被修改。
现在,如果我想修改切片本身,我显然不能这样做:
slice = append(slice, Point{99, 100})
Run Code Online (Sandbox Code Playgroud)
因为那只会重新定义切片变量,丢失原始引用。我知道我可以简单地做到这一点:
l.Points = append(l.Points, Point{99, 100})
Run Code Online (Sandbox Code Playgroud)
但是,在某些情况下,使用另一个变量而不是输入整个变量会更方便。
我试过这个:
*slice = append(*slice, Point{99, 100})
Run Code Online (Sandbox Code Playgroud)
但它不起作用,因为我试图取消引用显然不是指针的东西。 …