How can I declare global Error type in typescript NodeJs Architect project? - node.js

Context
Hi, I have a NodeJs+Ts+Architect setup for building and deploying lambda functions. Architect uses typescript plugin to compile typescript. I am trying to use Error class to throw errors.
However, Typescript is picking up Error type from
/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/lib.es5.d.ts.
In the image below, please note the constructor signature only accepts message field. And the error interface does not have an options object either. Please
look at Browser Error Class or NodeJs Error Class to see the signatures.
Node Error has the following constructor signature and Error interface.
Problem
Getting TS Error for trying to use constructor signature of Node Error as Typescript is reading Error type from lib.es5.d.ts which accepts only 1 argument
Possible Solutions which I know
Declare global Error type ( Need help here. Since Architect is compiling TS using its plugin, I am not able to declare and override Error interface )
Use your own Error class
I hope the question made sense. Would appreciate if there is a nicer way to solve this, but I am not getting ample discussions on Architect+Ts+NodeJs.

The cause option was introduced in ES2022. You would need to use at least that version for your lib types.
Change the lib version in your tsconfig.json to:
"compilerOptions": { "lib": ["es2022"] }

Related

How to find type definition file for xss-clean npm library

I just started to learn typescript and just started converting my nodejs/express application to typescript.
I have successfully got all types for the library using npm i #types/some-lib
only library, I can't find was npm i #types/xss-clean
where to find this library
import xss from 'xss-clean' //getting type definition error
app.use(xss())
If the library does not have many TypeScript users, chances are that no published types exist. In that case you can add your own to whatever degree of detail you wish.
You can create a type definition file, e.g. xss-clean.d.ts:
declare module 'xss-clean'
{
const value: Function;
export default value;
}
[More on declaration files]
You can use this page to look up if a package has types or not. xss-clean does not seem to have any types yet, so you would have to declare them by yourself.
More info on that here.

JHipster Entity sub generator - no properties in common with type 'Component'

I am having issues using the "entity" sub generator when attempting to update an existing entity.
When running the generator, at the end of the process, the following command is run:
yarn run cleanup && yarn run webpack:build:main
During this process I get these errors:
ERROR in [at-loader] dummy/path/car-delete-dialog.component.ts:58:23
TS2559: Type 'typeof CarDeleteDialogComponent' has no properties in common with type 'Component'.
ERROR in [at-loader] ./dummy/path/car-dialog.component.ts:147:27
TS2559: Type 'typeof CarDialogComponent' has no properties in common with type 'Component'.
ERROR in [at-loader] ./dummy/path/car-dialog.component.ts:150:27
TS2559: Type 'typeof CarDialogComponent' has no properties in common with type 'Component'.
Which can be fixed by changing:
his.modalRef = this.carPopupService
.open(CarDialogComponent, params['id']);
to:
this.modalRef = this.carPopupService
.open(CarDialogComponent as Component, params['id']);
These errors are just related to the entity that has been updated.
I understand why this has to be done but am unsure if this is something the generator etc should deal with.
JHipster version is 4.6.2 (I recently updated it) and I've not used the sub generator before as originally did an import from JDL studio.
Thanks in advance for any help you can give.
This has been resolved now.
I had a mismatch between the version the project was upgraded to (v4.6.2) and the global JHipster Generator (v4.6.1).
Updating the JHipster Generator version to v4.6.2 resolved the issues.

Why Acumatica can't find method

I'm working with Acumatica 5.30.2347. I have following selector in my graph:
var check = PXSelect<POLine,Where<POLine.orderType, Equal<POOrderType.regularOrder>>>
.Select(this);
but when I try to execute it, I receive following error:
Method not found: 'Void PX.Data.PXLineAttribute..ctor'(System.Type).
Initially I've got an impression, that this error message appeared because class PXLineAttribute doesn't have constructor which accepts System.Type, but with help of reflector I've discovered that PXLineAttribute has following declaration:
public PXLineNbrAttribute(System.Type sourceType)
: this(sourceType, false)
{
}
which gives me idea that PXLineNbrAttribute has needed constructor. So I have two questions: Why Acumatica Framework can't find constructor of PXLineNbrAttribute? How to help Acumatica to find before mentioned constructor?
Please check your VS class library project references to Acumatica assemblies. I would suspect them to reference assemblies from a different Acumatica build and therefore cause "Method not found ..." errors at runtime.

Groovy version downgrade 2.2.1

We have been building our application using groovy 2.3.6. Now because of some platform level issues we are advised to downgrade our groovy version to 2.2.1. I am facing no. of issues regarding this downgrade.
groovy is not able to infer the type of it variable in ver 2.2.1 so if i have code something like this
names.any { sliceName.endsWith(it) }
it gives me exception
[Static type checking] - Cannot find matching method java.lang.String#endsWith(java.lang.Object)
Secondly all the default method that i had used in collections no longer seem to exist
positions.any { it.primary }
groovy is unable to find the any method on list.
One way would be turn off static type checking, which will expose the code to a lot more runtime errors.
Is there any way to resolve these errors, without turning off static type checking. Also are these features only added in groovy 2.3.6 like default groovy methods and type inference for it variable
If you go back to an old version, old bugs will bite you.
Try giving the static compiler more of a hint
names.any { String it -> sliceName.endsWith(it) }

Referring to core modules from NativeScript UI plugin

I'm working on a UI component in VIM with TypeScript plugin that highlights the errors on the spot, so it's not something I get during the actual plugin installation into the app at this point (although I haven't tried yet).
declare module "card-view" {
import view = require("ui/core/view");
export class CardView extends view.View {
}
}
And I get this:
Cannot find module 'ui/core/view'.
I realize that ui/core/view is unavailable at this point, since it's a standalone plugin, but it will be available at runtime. Is there anything to be done to resolve the error? I must be missing some step that wasn't mentioned in the guide -- http://docs.nativescript.org/plugins/ui-plugin.
UPDATE 1:
When I got to card-view-common.js implementation I hit another issue. TypeScript expects android and ios properties to be implemented, but since the class extends View (from ui/core/view) they are supposed to be implemented there. In other words, I believe I still need to somehow point to the existing core module, not sure how though.
Found it. I added a devDependency to package.json with tns-core-modules like below, ran npm install and then it began recognizing the module. Makes sense if you think about how it is supposed to compile the module during the development phase without installing in the real app, but may be worth mentioning in the guide anyway.
"devDependencies": {
"tns-core-modules": "^1.5.1"
}
'ui/core/view' (and the modules, distributed through the tns-core-modules package are declared as ambient external modules.
It could be that the vim plugin you use does not recognize ambient modules correctly.

Resources