insidesherpa / JPMC-tech-task-3-PY3

8 stars 176 forks source link

Operator '+' cannot be applied to types 'Number' and 'Number'. TS2365 #18

Closed rohansingh3121 closed 4 years ago

rohansingh3121 commented 4 years ago

I have written this code on VSCode:

`import { ServerRespond } from './DataStreamer';

export interface Row { price_abc: number, price_def: number, ratio: number, timestamp: Date, upper_bound: number, lower_bound: number, trigger_alert: number | undefined, }

export class DataManipulator { static generateRow(serverRespond: ServerRespond[]): Row { const priceABC = (serverRespond[0].top_ask.price + serverRespond[0].top_bid.price) / 2; const priceDEF = (serverRespond[1].top_ask.price + serverRespond[1].top_bid.price) / 2; const ratio = priceABC / priceDEF; const upperBound = 1 + 0.05; const lowerBound = 1 - 0.05; return { price_abc: priceABC, price_def: priceDEF, ratio, timestamp: serverRespond[0].timestamp > serverRespond[1].timestamp ? serverRespond[0].timestamp : serverRespond[1].timestamp, upper_bound: upperBound, lower_bound: lowerBound, trigger_alert: (ratio > upperBound || ratio < lowerBound) ? ratio : undefined, } } }`

But the error comes out and saying this on the chrome browser:

Type error: Operator '+' cannot be applied to types 'Number' and 'Number'. TS2365

` 13 | export class DataManipulator { 14 | static generateRow(serverRespond: ServerRespond[]): Row {

15 | const priceABC = (serverRespond[0].top_ask.price + serverRespond[0].top_bid.price) / 2; | ^ 16 | const priceDEF = (serverRespond[1].top_ask.price + serverRespond[1].top_bid.price) / 2; 17 | const ratio = priceABC / priceDEF; 18 | const upperBound = 1 + 0.05;`

karanbodha commented 4 years ago

i am also facing the same error