Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. #2624

Closed
SomeKittens opened this issue Apr 5, 2015 · 5 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@SomeKittens
Copy link

I have the following code:

var blockLen = ecb.determineBlockSize();

var len = ecb.encrypt(Buffer.concat([mysteryBytes, mysteryBuffer])).length;

console.log(len, len/blockLen);

The signature of ecb.determineBlockSize is determineBlockSize (): Number {

However, I get an error on the console.log telling me that:

error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.

The return type is Number, the typeof reveals number, yet I still get this error.

tsc --version
message TS6029: Version 1.5.0-alpha
@DanielRosenwasser
Copy link
Member

Can you declare the return type of determineBlockSize as number instead of Number?

@SomeKittens
Copy link
Author

I don't get the error with number - what's the difference?

@DanielRosenwasser
Copy link
Member

The short version is that you should always be returning number instead of Number, string instead of String, boolean instead of Boolean, and usually almost anything else instead of Object (Note the casing for each name.)


In TypeScript, we have several primitive types like number, string, and boolean. They describe the type of values like 100.0, "hello", and true respectively. Their behavior with operators is as it's been defined in the specification. However, to determine whether a property access on them is valid (i.e. whether in the expression foo.x, it's valid to grab x off of foo), we get their apparent types, which are dependent on the interfaces Number, String and Boolean in lib.d.ts. These interfaces exist mainly to serve the apparent types of these primitives.

From the TypeScript spec:

For purposes of determining type relationships (section 3.10) and accessing properties (section 4.10), the Number primitive type behaves as an object type with the same properties as the global interface type 'Number'.

@SomeKittens
Copy link
Author

Ah, thanks. Misread the headings under "Basic Types" (which are capitalized) as the correct way to do things. Now seeing the code examples are lowercase.

@chanakaDe
Copy link

I also get the same issue here.
user_checking(registerdata, tested_users):boolean {
return registerdata.userid && typeof tested_users[registerdata.userid] == 'undefined';
}
can anyone tell me how to fix ?

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants