【发布时间】:2020-03-30 02:57:55
【问题描述】:
我在尝试导入分配给对象的模块时看到此错误:
// keys.js
export default {
SHOPIFY_API_KEY: "removed"
// more keys removed
}
// globalTypings.d.ts
declare module 'nonce' {
export default function nonce(length?: number): string
}
declare module "keys" {
export default interface keys {
SHOPIFY_API_KEY : string
, SHOPIFY_API_SECRET : string
, SCOPES : string
, CLIENT_APP_URL : string
}
}
// index.ts
import keys from "../keys.js";
// TS7016: Could not find a declaration file for module '../keys.js'. 'removed/keys.js' implicitly has an 'any' type
nonce 模块正在工作。我只包括它,以防多个声明是禁止的。上面我推测的语法错误的根源是什么?
**也试过了**
import * as keys from "../keys.js";
同样的错误结果
import {keys} from "../keys.js";
// and default keyword is removed from the interface declaration
同样的错误。
// inside the d.ts file
declare module "keys" {
export interface keys {
SHOPIFY_API_KEY : string
, SHOPIFY_API_SECRET : string
, SCOPES : string
, CLIENT_APP_URL : string
}
}
// TS1039: Initializers are not allowed in ambient contexts.
const keyObj: keys = {
SHOPIFY_API_KEY : "val"
, SHOPIFY_API_SECRET : "val"
, SCOPES : "val"
, CLIENT_APP_URL : "val"
};
【问题讨论】:
-
你试过在你的模块声明中使用
removed/keys.js吗? -
@AlanBirtles 我写了一个类似于 keys.js 中的虚拟对象,并用结果更新了帖子
标签: typescript .d.ts