如何修复这些打字稿错误?

How do I fix these typescript errors?

类型'string'不满足约束条件'unknown[]':

const query = db.prepareQuery<string>(

TS2707 [错误]:通用类型 'RouterContext<R, P, S>' 需要 1 到 3 个类型参数。

{ request, response, state }: RouterContext,

TS2532 [错误]:对象可能是 'undefined'。

data.negative = negative.map((w) => w.word);

我有一个 deno api 使用 oak,当我最近升级到 Deno 1.18 时,我现在遇到了所有这些错误。

下面是RouterContext的界面


export interface RouterContext<
  R extends string,
  P extends RouteParams<R> = RouteParams<R>,
  // deno-lint-ignore no-explicit-any
  S extends State = Record<string, any>,
> extends Context<S> {
  /** When matching the route, an array of the capturing groups from the regular
   * expression. */
  captures: string[];

  /** The routes that were matched for this request. */
  matched?: Layer<R, P, S>[];

  /** Any parameters parsed from the route when matched. */
  params: P;

  /** A reference to the router instance. */
  router: Router;

  /** If the matched route has a `name`, the matched route name is provided
   * here. */
  routeName?: string;

  /** Overrides the matched path for future route middleware, when a
   * `routerPath` option is not defined on the `Router` options. */
  routerPath?: string;
}

至于如何解决错误,你可以通过在接口中给它类型来解决它,如果你不想使用类型你可以用下面的代码替换它,

{ request, response, state }: RouterContext<string,any,any>,