我想在我的 typescript Nodejs 项目中有顶级的等待。
我的 tsconfig 过去看起来像这样:
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"lib": [
"dom",
"es6",
"es2017",
"esnext.asynciterable"
],
"skipLibCheck": true,
"sourceMap": true,
"outDir": "./dist",
"moduleResolution": "node",
#### other stuff which I think is not relevant removed ####
Run Code Online (Sandbox Code Playgroud)
我现在把它切换到
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"lib": [
"dom",
"es6",
"es2017",
"esnext.asynciterable"
],
"skipLibCheck": true,
"sourceMap": true,
"outDir": "./dist",
"moduleResolution": "node",
#### other stuff which I think is not relevant removed ####
Run Code Online (Sandbox Code Playgroud)
我还添加到"type": "module"了我的 package.json 中。事实上我现在有能力做顶级的等待 …
我想创建一个带有 tailwind css 的网格,其中第一列非常窄,第二列非常宽。通常我发现顺风文档非常直观,但我不理解这个。使用grid-cols-{n}我可以创建相同大小的列,但我不明白如何创建不同大小的列。我该怎么办?
DataSourceOptions在 typeORM 文档中,可以根据https://github.com/typeorm/typeorm/blob/master/docs/data-source-options.md添加 cli 参数。我在https://typeorm.io/using-cli上看到的示例看起来是
{
cli: {
entitiesDir: "src/entity",
subscribersDir: "src/subscriber",
migrationsDir: "src/migration"
}
}
Run Code Online (Sandbox Code Playgroud)
我在我的代码中尝试了这一点,如下所示:
let dataSource = new DataSource(
{
type: 'postgres',
host: 'localhost',
port: 5432,
database: 'website',
username: 'test',
password: 'test',
logging: true,
synchronize: false,
entities: [User, Posts],
cli: {
entitiesDir: "src/entity",
subscribersDir: "src/subscriber",
migrationsDir: "src/migration"
}
})
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误: 类型的参数'{ type: "postgres"; host: string; port: number; database: string; username: string; password: string; logging: true; synchronize: false; entities: (typeof User | …
在下面的代码中,我尝试对于 的每个属性foo,检查 中的属性是否bar为nullish,如果是,则bar使用 中的属性覆盖 的该属性foo。
type fooType = {
a?: string
b?: number
}
type barType = fooType & {
c: string
}
const foo: fooType = {
a: 'hello',
b: 5,
}
const bar: barType = {
a: 'greetings',
b: undefined,
c: 'not in foo',
}
const fooKeys = Object.keys(foo) as Array<keyof typeof foo>
fooKeys.forEach((k) => {
bar[k] ??= foo[k]
})
Run Code Online (Sandbox Code Playgroud)
我收到错误:Type 'string' is not assignable to type …
我\xe2\x80\x99m 试图更好地理解顺风网格 - 有人可以帮助我理解每个参数1fr和中的700px作用2fr
\n<!-- Complex grids -->\n<div class="grid-cols-[1fr,700px,2fr]">\n <!-- ... -->\n</div>\n\nRun Code Online (Sandbox Code Playgroud)\n 在下面的代码中,即使我们将其用作函数的输入,也将始终分配 ab类型。有没有一种方法可以实现一些智能打字稿魔法,例如使用泛型,以便根据函数输入分配正确的类型?number | stringbstringFormat.hexb
enum Format{
hex,
integer
}
function fun (a: Format){
const k = Math.floor(Math.random()*100)
if (a === Format.hex) {
return k.toString(16)
}
else {
return k
}
}
const b = fun(Format.hex)
Run Code Online (Sandbox Code Playgroud) 假设我有一个类型
type A = {
a: string
b?: number
c: boolean
d?: string
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能从中派生出一个类型,我只需要a并且b将其他所有内容保留为可选
type A2 = {
a: string
b: number
c?: boolean
d?: string
}
Run Code Online (Sandbox Code Playgroud)
我的方法是:
export type WithRequiredOnly<T, K extends keyof T> = T & { [P in K]-?: T[P] } & { [P in Exclude<keyof T, K>]+?: T[P] }
A2 = WithRequiredOnly<A, 'a'|'b'>
Run Code Online (Sandbox Code Playgroud)
但这似乎还需要其他字段......