how do i solve the "statements are not allowed in ambient contexts" error


I am working on a small project which in itself has a backend project and a front end project in it. I was using a module called ‘ml-random-forest’ in frontend project but because the module’s extensive calculation would freeze the UI , i decided to take the calculation to backend project and call it via fetch request. For this purpose I created a backend with nestJs and imported the ml-random-forest module in my trainerSerivice.ts. now when I run the backend project it gives me the below errors.

node_modules/ml-random-forest/types/types.d.ts:25:6 - error TS1036: Statements are not allowed in ambient contexts.

25     };
        ~
node_modules/ml-random-forest/types/types.d.ts:27:22 - error TS2304: Cannot find name 'DecisionTreeClassifier'.

27     type Estimator = DecisionTreeClassifier | DecisionTreeRegression;
                        ~~~~~~~~~~~~~~~~~~~~~~
node_modules/ml-random-forest/types/types.d.ts:27:47 - error TS2304: Cannot find name 'DecisionTreeRegression'.

27     type Estimator = DecisionTreeClassifier | DecisionTreeRegression;
                                                 ~~~~~~~~~~~~~~~~~~~~~~
node_modules/ml-random-forest/types/types.d.ts:29:36 - error TS2689: Cannot extend an interface 'RandomForestBaseOptions'. Did you mean 'implements'?    

29     class RandomForestBase extends RandomForestBaseOptions {
                                      ~~~~~~~~~~~~~~~~~~~~~~~
node_modules/ml-random-forest/types/types.d.ts:175:5 - error TS2666: Exports and export assignments are not permitted in module augmentations.

175     export { RandomForestClassifier, RandomForestRegression }
        ~~~~~~

Found 5 error(s).

what i dont’ understand is that why the typescript consider as a declaration file?

Source: React – Stack Overflow

November 11, 2021
Category : News
Tags: ml | nestjs | reactjs | typescript

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.