我有一个bottomTabNavigator,它有两个stacknavigator。每个 stacknavigator 都有自己各自的屏幕。每当我使用类似的东西
navigator.navigate("Stackname" {screen:"screenname", randomProp: "seomthing")
Run Code Online (Sandbox Code Playgroud)
参数被发送到 stacknavigator,而不是屏幕本身。我通过传递解决了这个问题
initialParams=route.params
Run Code Online (Sandbox Code Playgroud)
在堆栈导航器中,但是当我第二次调用第一个代码块时它们不会刷新。有任何想法吗?
答案:你不能
从这里我知道要检查一个值是否是一个列表,您可以使用 Array.isArray() 但我有一个奇怪的情况,我有一个查询函数
export async function query<T = unknown>(sql: string, options?: unknown): Promise<T> {
const pool = await initializePool()
const result = await pool.query(sql, options);
return /* T is of type list */ ? result : [result];
}
Run Code Online (Sandbox Code Playgroud)
我不能在类型上使用 Array.isArray(),我想知道是否有某种 typeof 函数可以在 T 上使用。
问题是, pool.query 总是返回一个数组,如果可能的话我想立即解构它
const initializePool = async () => {
if (pool) {
return pool;
}
const CREDS = { connectionLimit: 500000, ...MYSQL_CREDS, multipleStatements: true }
pool = await mysql.createPool(CREDS)
return pool
}
Run Code Online (Sandbox Code Playgroud) 我目前有一个设置,我启动几个异步请求并在最后等待 Promise.all() 。然而 Typescript 仍然认为承诺尚未兑现。
例子:
const Promise1 = someAsync()
const Promise2 = someAsync()
const Promise3 = someAsync()
await Promise.all([Promise1, Promise2, Promise3])
console.log(Promise1.someData) // is a problem
Run Code Online (Sandbox Code Playgroud)
我想我可以在控制台日志中再次等待 Promise1,但这似乎有点不完整,有什么想法吗?或者我在 console.log 点解析 Promise1 是错误的吗?