I'm not sure what part of this process is failing but I would appreciate any sort of help on this.
I have a vendor library (BigDecimal.js) that I'm attempting to import and use in my angular2 application. I can get it to transpile just fine by adding a definition file in my typings directory (I also tried it in my source directory) but webpack doesn't add the variable injection into the source file. (I guess it's just assuming that it's declared globally).
If it helps, here is the definition file thus far:
declare namespace BigDecimalLibrary {
interface MathContext {
ROUND_CEILING: number
ROUND_DOWN: number
ROUND_FLOOR: number
ROUND_HALF_DOWN: number
ROUND_HALF_EVEN: number
ROUND_HALF_UP: number
ROUND_UNNECESSARY: number
ROUND_UP: number
// TODO: Populate this if we ever need it
}
interface BigDecimal {
// CONSTANTS
ROUND_CEILING: number
ROUND_DOWN: number
ROUND_FLOOR: number
ROUND_HALF_DOWN: number
ROUND_HALF_EVEN: number
ROUND_HALF_UP: number
ROUND_UNNECESSARY: number
ROUND_UP: number
ZERO: BigDecimal
ONE: BigDecimal
TEN: BigDecimal
// INSTANCE METHODS
div(a:number, b: number): number
abs(context?: MathContext): BigDecimal
add(rhs: BigDecimal, context?: MathContext): BigDecimal
compareTo(rhs: BigDecimal, context?: MathContext): number
divide(rhs: BigDecimal, context?: MathContext): BigDecimal
divideInteger(rhs: BigDecimal, context?: MathContext): BigDecimal
max(rhs: BigDecimal, context?: MathContext): BigDecimal
min(rhs: BigDecimal, context?: MathContext): BigDecimal
multiply(rhs: BigDecimal, context?: MathContext): BigDecimal
negate(context?: MathContext): BigDecimal
plus(context?: MathContext): BigDecimal
pow(rhs: BigDecimal, context?: MathContext): BigDecimal
remainder(rhs: BigDecimal, context?: MathContext): BigDecimal
subtract(rhs: BigDecimal, context?: MathContext): BigDecimal
equals(rhs: BigDecimal, context?: MathContext): boolean
format(before: number, after: number, explaces?: number, exdigits?: number, exform?: number, exround?: number): string
intValueExact(): number
movePointLeft(digits: number): BigDecimal
movePointRight(digits: number): BigDecimal
scale(): number
setScale(scale: number, round?: number): BigDecimal
signum(): number
toString(): string
round(precision: number, mode: number): BigDecimal
isGreaterThan(rhs: BigDecimal): boolean
isLessThan(rhs: BigDecimal): boolean
isGreaterThanOrEqualTo(rhs: BigDecimal): boolean
isLessThanOrEqualTo(rhs: BigDecimal): boolean
isPositive(): boolean
isNegative(): boolean
isZero(): boolean
}
interface BigDecimalStatic {
// CONSTANTS
ROUND_CEILING: number
ROUND_DOWN: number
ROUND_FLOOR: number
ROUND_HALF_DOWN: number
ROUND_HALF_EVEN: number
ROUND_HALF_UP: number
ROUND_UNNECESSARY: number
ROUND_UP: number
ZERO: BigDecimal
ONE: BigDecimal
TEN: BigDecimal
new (number: string|string[], offset?: number, length?: number): BigDecimal
}
}
declare module 'big-decimal' {
var BigDecimal: BigDecimalLibrary.BigDecimalStatic;
export = BigDecimal;
}
declare var BigDecimal: BigDecimalLibrary.BigDecimalStatic;
At the top of my ts files, I'm using the following to import the class:
import BigDecimal = BigDecimalLibrary.BigDecimal;
I've tried copying the directory to a vendor directory and just doing an npm install big-decimal
. Is there something I need to configure in webpack? I'm just lost as to where to even begin.
EDIT
I've been able to work around this issue by using the following:
import BigDecimalType = bigdecimal.BigDecimal;
const BigDecimal = require('big-decimal').BigDecimal;
And replacing all type references with "BigDecimalType" and leaving the remaining references alone. This is not ideal but will work for now.