Javascript 使用导出默认语法向普通JS模块添加键入

Javascript 使用导出默认语法向普通JS模块添加键入,javascript,typescript,typescript-typings,Javascript,Typescript,Typescript Typings,我想向“cipher collection”(密码集合)节点模块添加键入,但它不起作用,我不知道如何执行此操作。我看了一下ressouces[1][2][3],并看了一下它在RxJs中是如何实现的,但我仍然无法将其适应此模块 cipher集合有一个src文件夹,例如base64.js位于: node\u模块/cipher集合/src/base64.js: import { isBrowser } from './helpers/index' // Courtesy: https://devel

我想向“cipher collection”(密码集合)节点模块添加键入,但它不起作用,我不知道如何执行此操作。我看了一下ressouces[1][2][3],并看了一下它在RxJs中是如何实现的,但我仍然无法将其适应此模块

cipher集合有一个src文件夹,例如base64.js位于:

node\u模块/cipher集合/src/base64.js:

import { isBrowser } from './helpers/index'

// Courtesy: https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem

const decode = input => isBrowser ? decodeURIComponent(atob(input).split('').map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)).join('')) : atob(input)
const encode = input => isBrowser ? btoa(encodeURIComponent(input).replace(/%([0-9A-F]{2})/g, (match, p1) => String.fromCharCode(`0x${p1}`))) : btoa(input)

const btoa = isBrowser ? window.btoa : i => Buffer.from(i).toString('base64')
const atob = isBrowser ? window.atob : i => Buffer.from(i, 'base64').toString()

export default {
  decode,
  encode
}
我尝试添加具有以下内容的文件
node\u modules/cipher collection/index.d.ts

export namespace CipherCollection {
  export { base64 } from './src/base64';
}
src/base64.d.ts

export namespace base64 {
  export function encode(obj: any): string;
  export function decode(obj: string): any;
}
我想我现在可以使用base64,例如:

import { base64 } from 'cipher-collection';
base64.encode("hello!");
import { CipherCollection } from 'cipher-collection';
CipherCollection.base64.encode("hello!");
或者像这样:

import { base64 } from 'cipher-collection';
base64.encode("hello!");
import { CipherCollection } from 'cipher-collection';
CipherCollection.base64.encode("hello!");
但是typescript找不到base64。有什么办法可以做到这一点吗

[1]

[2]

[3]