小编pos*_*ita的帖子

TypeScript 如何为泛型函数创建泛型类型别名?

给定一个类型化的泛型函数,我想为该函数创建一个泛型别名,但似乎我不能。换句话说,这不起作用:

// foo.tsx
function foo<T>(arg: T): T {
  return arg
}

type FooT = typeof foo  // works, but alias isn't generic: <T>(arg: T) => T
type FooParametersT = Parameters<typeof foo>  // sure: [unknown]
type FooReturnT = ReturnType<typeof foo>  // no problem: unknown

type GFooT<T,> = typeof foo<T,>  // yikes
type GFooParametersT<T,> = Parameters<typeof foo<T,>>  // nope
type GFooReturnT<T,> = ReturnType<typeof foo<T,>>  // fails
Run Code Online (Sandbox Code Playgroud)

我真正想做的是在别人的库中获取函数的类型,然后围绕它构建一个接口。例如:

import { useState } from "react"

type UseStateFnT<T,> = typeof useState<T>
const wrapUseState: (toWrap: UseStateFnT<T,>) …
Run Code Online (Sandbox Code Playgroud)

generics typescript

15
推荐指数
1
解决办法
3956
查看次数

“ gcloud.datastore”在哪里保留其本地开发状态,如何清除它?

我正在尝试使用Google App Engine的灵活Python 3环境和Cloud Datastore。在本地进行测试时,这(通常)要求在Gunicorn之类的应用中运行您的应用,并从中访问Datastore API gcloud.datastore。例如:

import gcloud.datastore as g_datastore
ds = g_datastore.Client(...)
entity = datastore.Entity(key=ds.key(...))
ds.put(entity)
Run Code Online (Sandbox Code Playgroud)

在本地运行(在开发人员模式下)时,实体的状态会在两次运行之间保持不变。我一辈子都无法弄清楚它们的存储位置或如何清除在创建/访问后创建的dev数据存储gcloud.datastore.Client。据我所知,它使用的位置与ndb通过via运行时所使用的位置不同dev_appserver.py

我已经尝试通过以下方式解决问题(运行OS X时):

$ touch foo
$ GCLOUD_PROJECT=... python .../main.py
 * Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger pin code: ...
127.0.0.1 - - [04/Jul/2016 10:36:01] "GET / HTTP/1.1" 200 -
...
^C
$ sudo find /private/tmp /var/db /var/tmp ~/.config/gcloud ~/Library -newer foo …
Run Code Online (Sandbox Code Playgroud)

google-cloud-datastore google-app-engine-python app-engine-flexible

3
推荐指数
1
解决办法
196
查看次数