小编Lak*_*ton的帖子

带有默认参数值的打字稿条件返回类型

我试图让函数根据参数值返回一个条件类型,但参数的默认值是:

function myFunc<T extends boolean>(myBoolean: T = true): T extends true 
       ? string 
       : number {
       return  myBoolean ? 'string' : 1
    }
Run Code Online (Sandbox Code Playgroud)

这会引发错误 Type 'true' is not assignable to type 'T'. 'true' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'boolean'.

我不明白这个错误,因为它T是一个布尔值,我怎么不能分配true给它?

我尝试了另一种函数重载方法:

function myFunc(myBool: true): string
function myFunc(myBool: false): number
function myFunc(myBool = true) {
       return  myBool ? 'string' : 1
    }

myFunc() …
Run Code Online (Sandbox Code Playgroud)

typescript

7
推荐指数
1
解决办法
1088
查看次数

OSX 上的 DBeaver - 返回空连接

我无法在 osx(最新版本)上使用 DBeaver 连接到 postgreSQL 数据库并获得此神秘信息 null connection returned

但是,我可以毫无问题地与 teamSQL 连接。

我检查了大量资源,但我不知道这个问题的原因,所以我的连接信息是正确的。

有关信息,我已安装 java:

java -version
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
Run Code Online (Sandbox Code Playgroud)

java postgresql macos dbeaver

5
推荐指数
1
解决办法
5758
查看次数

角queryParamMap为空,然后填充

我在应用程序中创建了一个新模块,因此我可以将不需要通信的部分分开,并使用其自己的路由模块和组件创建了一个new.module.ts:

new-routing.module.ts

const exportRoutes: Routes = [
  {
    path: 'export',
    component: ExportsComponent
  }
]

@NgModule({
  imports: [RouterModule.forRoot(exportRoutes)],
  exports: [RouterModule]
})
export class ExportRoutingModule {}
Run Code Online (Sandbox Code Playgroud)

new.module.ts

import { Router } from '@angular/router'
import { BrowserModule } from '@angular/platform-browser'

// Routing Module
import { NewRoutingModule } from './new-routing.module'

@NgModule({
  imports: [..., ExportRoutingModule, ...],
  declarations: [ExportsComponent],
  bootstrap: [ExportsComponent]
})
Run Code Online (Sandbox Code Playgroud)

我有一个简单的index.html

<body class="app">
  <router-outlet></router-outlet> // outlet is here because I read that I needed it to be able to use …
Run Code Online (Sandbox Code Playgroud)

angular2-routing angular

5
推荐指数
1
解决办法
3071
查看次数