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 TS2339: Property 'subset' does not exist on type 'MathType'. Property 'subset' does not exist on type 'number'. #2606

Closed
topazus opened this issue Jun 26, 2022 · 2 comments

Comments

@topazus
Copy link

topazus commented Jun 26, 2022

import * as math from "mathjs"
const d = math.matrix([
  [1, 2],
  [3, 4],
])
var res = math.dotPow(d, 2)
console.log(res.subset(math.index(1, 1)))

run js code, get the expected result: print 16

When I put the same js code in ts file

t1.ts file

import * as math from "mathjs"
const d = math.matrix([
  [1, 2],
  [3, 4],
])
var res = math.dotPow(d, 2)
console.log(res.subset(math.index(1, 1)))

and run ts-node t1.ts

,but get the following output errors:

/Users/felix/.nvm/versions/node/v18.4.0/lib/node_modules/ts-node/src/index.ts:843
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
t1.ts:7:17 - error TS2339: Property 'subset' does not exist on type 'MathType'.
  Property 'subset' does not exist on type 'number'.

7 console.log(res.subset(math.index(1, 1)))
                  ~~~~~~

    at createTSError (/Users/felix/.nvm/versions/node/v18.4.0/lib/node_modules/ts-node/src/index.ts:843:12)
    at reportTSError (/Users/felix/.nvm/versions/node/v18.4.0/lib/node_modules/ts-node/src/index.ts:847:19)
    at getOutput (/Users/felix/.nvm/versions/node/v18.4.0/lib/node_modules/ts-node/src/index.ts:1057:36)
    at Object.compile (/Users/felix/.nvm/versions/node/v18.4.0/lib/node_modules/ts-node/src/index.ts:1411:41)
    at transformSource (/Users/felix/.nvm/versions/node/v18.4.0/lib/node_modules/ts-node/src/esm.ts:400:37)
    at /Users/felix/.nvm/versions/node/v18.4.0/lib/node_modules/ts-node/src/esm.ts:278:53
    at async addShortCircuitFlag (/Users/felix/.nvm/versions/node/v18.4.0/lib/node_modules/ts-node/src/esm.ts:409:15)
    at async ESMLoader.load (node:internal/modules/esm/loader:431:20)
    at async ESMLoader.moduleProvider (node:internal/modules/esm/loader:350:11)
    at async link (node:internal/modules/esm/module_job:70:21) {
  diagnosticCodes: [ 2339 ]
}
@josdejong
Copy link
Owner

The reason is that the method .subset() is only available on a Matrix, and the output of math.dotPow is currently not specific enough to know that it res is indeed a Matrix.

Here is the current type definition of dotPow:

dotPow(x: MathType, y: MathType): MathType

This definition should be changed similar to most functions (like exp that is right below it):

mathjs/types/index.d.ts

Lines 1093 to 1097 in ead6228

exp(x: number): number
exp(x: BigNumber): BigNumber
exp(x: Complex): Complex
exp(x: MathArray): MathArray
exp(x: Matrix): Matrix

Anyone able to improve the type definitions of dotPow and also dotMultiply and dotDivide?

@josdejong
Copy link
Owner

Fixed now in v11.5.1 via #2890.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants