我正在尝试在 Angular Last 版本项目中使用http://hashids.org 。
我找到了这个定义文件:
// Type definitions for Hashids.js 1.x
// Project: https://github.com/ivanakimov/hashids.node.js
// Definitions by: Paulo Cesar <https://github.com/pocesar>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
export default class Hashids {
private version: string;
private minAlphabetLength: number;
private sepDiv: number;
private guardDiv: number;
private errorAlphabetLength: string;
private errorAlphabetSpace: string;
private alphabet: string[];
private seps: string;
private minHashLength: number;
private salt: string;
constructor(salt: string, minHashLength?: number, alphabet?: string);
public decode(hash: string): number[];
public encode(arg: number): string;
public encode(arg: number[]): string;
public encode(...args: number[]): string;
public encodeHex(str: string): string;
public decodeHex(hash: string): string;
public hash(input: number, alphabet: string): string;
public unhash(input: string[], alphabet: string): number;
}
但是当我尝试使用以下代码在我的 Angular 项目中使用时:
import * as Hashids from 'hashids';
export abstract class BaseService {
protected getId(id: any) {
const x = new Hashids('somesecretec');
return x.encode(id);
}
}
我收到了这个错误:
错误 TS2351:不能将“new”与类型缺少调用或构造签名的表达式一起使用。
在我的本地它可以正常工作,没有问题。但我试图编译一个生产设置,但它不起作用。