Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript TS7016:找不到模块';的声明文件/moduleName.js'。。。具有任何类型的隐式_Typescript_.d.ts - Fatal编程技术网

Typescript TS7016:找不到模块';的声明文件/moduleName.js'。。。具有任何类型的隐式

Typescript TS7016:找不到模块';的声明文件/moduleName.js'。。。具有任何类型的隐式,typescript,.d.ts,Typescript,.d.ts,当我尝试导入分配给对象的模块时,我看到此错误: // 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 defau

当我尝试导入分配给对象的模块时,我看到此错误:

// 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"
};

通过一些重构解决了这个问题。密钥更改似乎是将keys.js切换到keys.ts,这样它就可以接受来自
global.d.ts
文件的接口:

// global.d.ts
declare module "keys" {
 interface KeysInterface {
  SHOPIFY_API_KEY : string
  , SHOPIFY_API_SECRET : string
  , SCOPES : string
  , CLIENT_APP_URL : string
 }

 export default KeysInterface;
}

// keys.ts
const keysObj = {
  SHOPIFY_API_KEY: "removed"
  , SHOPIFY_API_SECRET: "removed"
  , SCOPES: "removed"
  , CLIENT_APP_URL: "removed"
};

export default keysObj;


// index.ts
import keys from "../keys";


你试过在你的模块声明中使用
removed/keys.js
吗?@AlanBirtles我写了一个类似于keys.js中的虚拟对象,并用结果更新了帖子