有一些方法可以返回字段包含某些值的项目吗?例如.
GET /people?contains="foo"
返回名称中包含"foo"字样的所有人.
提前致谢
我从 React 和 Typescript 开始,我的代码编辑器声称我的 Button 组件(错误如下),但似乎eslint没问题。
import React from 'react'
interface Props {
children: React.ReactChild | React.ReactChildren
}
const Button: React.FunctionComponent = ({ children }: Props) => {
return <button>{children}</button>
}
export default Button
Run Code Online (Sandbox Code Playgroud)
错误:
Type '({ children }: Props) => JSX.Element' is not assignable to type 'FunctionComponent<{}>'.
Types of parameters '__0' and 'props' are incompatible.
Type '{ children?: ReactNode; }' is not assignable to type 'Props'.
Types of property 'children' are incompatible.
Type 'ReactNode' is not …Run Code Online (Sandbox Code Playgroud) 我想知道如何修复此代码,如果我将房间类型更改为字符串,forEach((room: string)则会出现此错误:
类型“(room: string) => void”的参数不可分配给类型“(value:unknown,index:number,array:unknown[])=>void”的参数。参数“room”和“value”的类型不兼容。类型“未知”不可分配给类型“字符串”。
否则,如果我留空,我就必须room as string在线转换batch.update。
Object.values(users).forEach((room: string) => {
batch.set(firestore.collection('messages').doc(), {
...message,
room,
})
batch.update(firestore.collection('rooms').doc(room), { // if I leave room as `unknow` I have an error here.
...
})
})
Run Code Online (Sandbox Code Playgroud)
修复打字的正确方法是什么?
我有一个在 Google Cloud Functions 上的 NodeJS 14 上运行的代码,我正在使用typescript来tsc编译我的代码。
import qs from 'qs'
console.log(`qs >>> ${qs})
Run Code Online (Sandbox Code Playgroud)
上面的代码记录(在生产中)
qs >>> 未定义
我认为问题出在我的身上tsconfig,有人可以帮忙检查我的配置中是否有一些不常见的东西吗?
如果我使用require('qs')代码有效。
我的tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017",
"allowSyntheticDefaultImports": true
},
"compileOnSave": true,
"include": ["src", "tests"]
}
Run Code Online (Sandbox Code Playgroud) 我想从对象中删除所有空值。我们假设:
const data = {
key1: 'ok',
key2: null,
key3: '', // should be removed too
key4: {
inner_key1: 'aaa',
inner_key2: null
}
}
Run Code Online (Sandbox Code Playgroud)
我所做的是这个
const clean = R.reject(R.either(R.isNil, R.isEmpty))
Run Code Online (Sandbox Code Playgroud)
还有这个作品:
{"key1":"ok","key4":{"inner_key1":"aaa","inner_key2":null}}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,除了嵌套对象之外,inner_key2 也存在,并且应该被过滤掉。
使用 ramda,我怎样才能删除这个嵌套值?
我将 Cloud Scheduler 与 PubSub 和 Cloud Run 结合使用。
有时,即使在 Cloud Run 上运行的服务成功响应(HTTP 204 无内容),我的服务也会被触发多次。
我的服务花了大约 200 秒来响应 PubSub 发出的 POST。
我的问题是:如何限制 PubSub 的尝试次数?或者我犯了一些错误,比如多个订阅(我只有一个订阅,只是在控制台上检查过)?
奇怪的是,当我触发 Cloud Scheduler 时,PubSub 多次调用我的服务(参见下面的屏幕截图)
我正在部署我的 PubSub 和 Cloud Run,如下所示:
export PROJECT_ID=...
export PROJECT_NUMBER=$(gcloud projects describe --format 'value(projectNumber)' ${PROJECT_ID})
Run Code Online (Sandbox Code Playgroud)
设置 Cloud Scheduler(每个项目只需完成一次)
gcloud pubsub topics create supervisor-cron --project ${PROJECT_ID}
Run Code Online (Sandbox Code Playgroud)
创建 Pub/Sub 订阅
gcloud pubsub subscriptions create supervisor-subscription \
--topic supervisor-cron \
--project ${PROJECT_ID}
Run Code Online (Sandbox Code Playgroud)
在https://console.cloud.google.com/cloudscheduler创建 Cloud Scheduler
启用 Pub/Sub 在您的项目中创建身份验证令牌
gcloud projects add-iam-policy-binding ${PROJECT_ID} \ …Run Code Online (Sandbox Code Playgroud) 我的项目中有以下行
from requests.packages.urllib3.util.retry import Retry
Run Code Online (Sandbox Code Playgroud)
与工作相关的所有内容都requests没有问题,甚至重试
from requests import Session
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
requests = Session()
retry = Retry(connect=8, backoff_factor=0.5)
adapter = HTTPAdapter(max_retries=retry)
requests.mount("http://", adapter)
requests.mount("https://", adapter)
Run Code Online (Sandbox Code Playgroud)
但由于某种未知的原因,Pylance 抱怨Retry找不到模块。
这个警告可能是什么?
我有一个使用 Firebase Admin 上的默认存储桶的项目。
我有以下几行:
const [url] = await blob.getSignedUrl({ action: 'read', expires: Date.now() + 60 * 1000, contentType: mimetype })
Run Code Online (Sandbox Code Playgroud)
当调用我的 HTTPS 可调用函数时,上面的行会抛出以下错误:
Unhandled error Error: The caller does not have permission
at Gaxios._request (/workspace/node_modules/gaxios/build/src/gaxios.js:129:23)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Compute.requestAsync (/workspace/node_modules/google-auth-library/build/src/auth/oauth2client.js:368:18)
at async GoogleAuth.signBlob (/workspace/node_modules/google-auth-library/build/src/auth/googleauth.js:655:21)
at async sign (/workspace/node_modules/@google-cloud/storage/build/src/signer.js:97:35) {
name: 'SigningError'
}
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
使用安装 bcrypt 或 argon2 时npm install --ignore-scripts --omit=dev出现错误
app-1 | node:internal/modules/cjs/loader:998
app-1 | throw err;
app-1 | ^
app-1 |
app-1 | Error: Cannot find module './lib/binding/napi-v3/argon2.node'
app-1 | Require stack:
app-1 | - /app/node_modules/argon2/argon2.js
Run Code Online (Sandbox Code Playgroud)
可能是什么问题,或者如何解决?
使用字典理解是否可以将所有值递归转换为字符串?
我有这本词典
d = {
"root": {
"a": "1",
"b": 2,
"c": 3,
"d": 4
}
}
Run Code Online (Sandbox Code Playgroud)
我试过
{k: str(v) for k, v in d.items()}
Run Code Online (Sandbox Code Playgroud)
但是上面的代码将整个root值转换为字符串,我想要这个:
d = {"root": {"a": "1", "b": "2", "c": "3", "d": "4"}}
Run Code Online (Sandbox Code Playgroud)