我正在尝试将Typescript 2.0的已区分联合类型与RxJS一起使用,但是却收到一个错误,即我返回的对象不是联合类型的类型之一。
这是我的类型:
interface Square {
kind: "square";
width: number;
}
interface Circle {
kind: "circle";
radius: number;
}
interface Center {
kind: "center";
}
type Shape = Square | Circle | Center;
Run Code Online (Sandbox Code Playgroud)
我只返回一个Shape不使用Observable编译器的函数完全可以:
function shapeFactory(width: number): Shape {
if (width > 5) {
return {kind: "circle", radius: width};
} else if (width < 2) {
return {kind: "square", width: 3};
}
return {kind: "center"};
}
Run Code Online (Sandbox Code Playgroud)
当我改为尝试返回Observable<Shape>类似的内容时:
function shapeFactoryAsync(width: number): Observable<Shape> {
if (width …Run Code Online (Sandbox Code Playgroud) 使用 Goland 时,根据我连接的数据源获取 SQL 语法突出显示和自动完成非常有用。不幸的是,这似乎只在我使用标准 Go sql 包时有效,而在我使用有效包装 sql 包调用的自定义包时不起作用。我想知道是否可以告诉 Goland 特定的函数/参数实际上是 SQL 查询/SQL 语句。
这是 Goland 的示例,允许对 sql.DB 结构上的方法进行 SQL 补全,而不允许在自定义 query.ReadOnlyDB 结构上补全: