WebStorm thinks record.save() is a a void function...
# suitescript
c
WebStorm thinks record.save() is a a void function despite the fact it returns an number. Am I not thinking about this properly or is WS wrong?
e
WebStorm is not identifying the correct
save()
method; you can see it's looking at the
save()
method of a
CanvasState
class.
c
Yup
e
So either it doesn't know that
newRefund
is an
N/record.Record
instance, or it isn't aware of
N/record
c
Can it not infer from this ?
e
Depends on what it thinks
record.create()
returns, I suppose
c
WS doesn't understand the code
Is there a dependency I haven't added to this project maybe?
No externa libraries..
Maybe I need to add the SS2.1 files?
e
Are you using the SDF plugin? If so, it should add the SS files for you, or you can add them explicitly in your External Libs
c
I am using the SDF plugin
e
You can explicitly tell it that
newRefund
is a record like
Copy code
/** @type {Record} */
var newRefund = ...
My WebStorm picks up the docs from both the SDF plugin and the
@oracle/suitecloud-unit-testing
package when I hit F3 on the
save()
method:
It doesn't just know that the
Record
instance is one, though
I can tell it as much, though
a
Something is not right with your project, if you create the project via WebStorm new project using the SDF Plugin it will properly recognize the NetSuite libraries etc. Please notice that refactoring and changing your project name and directory name breaks something, and the NetSuite SDF structure is lost somehow. I don't know what the issue is and I did not dig enough into it because is easily fixable by creating the project with the proper/desired name and copy the files.
e
If I had to guess, creating the project via the SDF New Project option (I don't do this myself) just adds the SS files to the External Libs of the project. If you want to link them manually, they're located at
<webstormInstallDir>\plugins\<http://com.netsuite.ide.webstorm.app|com.netsuite.ide.webstorm.app>\lib\instrumented-com.netsuite.ide.webstorm.app-2023.2.0.jar!\library\SuiteScript_2_0\
c
I created a new project. That's annoying though, having to .archive the old project name then move all the assets over to the new directory tree.
s
I still recommend using TypeScript for 'real' typechecking and use @hitc/netsuite-types
IMHO webstorm has amazing type 'guessing' capability for JS, but TS takes the cake by a long shot.
c
I am on a mission to introduce TS wherever I go
but sometimes I get pushback
a
I will push back until it is natively supported by NetSuite.
s
I'd argue that TS is emitting better standards compliant JS code than any of us are writing by hand. So in that sense it's more supported by NetSuite, given their standards oriented JS runtime?
a
And I agree 100% with you, I don't deny TS advantages, but until NetSuite provides official types or whatnot to use with TS I prefer to stay away from it, I don't like the idea of relying on an NPM package somebody created, mainly because NetSuite is not a Website is an ERP system that handles financial data and critical business data, so no, I don't like the idea of using node and installing no official NPM packages. But this is just me, old and paranoid soul... https://www.securityweek.com/dozens-of-malicious-npm-packages-steal-user-system-data/#:~:text=Fortinet%20warns%20of%20multiple%20malicious,designed%20to%20steal%20sensitive%20information.&amp;text=Fortinet's%20security%20researchers%20have%20identified,of%20information%20from%20victims'%20systems.
s
keep in mind that @hitc/netsuite-types is only type information. It doesn't add any code to your project that could get deployed to NetSuite.
c
Yeah, plus it’s hard for large clients with lots of corporate governance to approve something “non-standard” nobody gets fired for doing things how Oracle say they should be done
a
@Shawn Talbert There are many considerations, the example above is just one, another one is for example: If I manage a team of developers, is hard enough to find certified NetSuite Developers, if I move to TS now I need to find certified NetSuite Developers who also know TS, which no always the case since TS is not officially used by NetSuite and therefore no required for a Certification.
s
don't need 'certified NetSuite Developers'. I'd much rather get folks with decent ERP experience on any platform. Indeed, using TypeScript makes learning the platform and writing correct code significantly easier. memorizing APIs is not a competitive advantage 🙂
c
@Shawn Talbert is right, but corporate governance doesn’t care, “dem be the rulez”
a
@Shawn Talbert Sadly that is not how it works, when s… hit the fan it comes down to something like this: • Company lost XYZ amount of money or customers or deal because a code/script problem. • Who was the developer? Is she/he certified (yes or no)?. • Was she/he using NetSuite native API only?(NetSuite is the first one that will throw you under the bus and from the very beginning will say they don’t support TS and wash their hands). • If not certified then this comes into place: who hire her/him? • If no native API, who authorize it?
I don’t want to be a broken record here, but NetSuite is an ERP and handles money and money can be lost and relationships with customers can also be lost because of scripts, my personal preference will always be to stay with what is native/supported.
👍🏻 1
👍 1
c
TS is better though 😄
But you’re not wrong. It depends on the customer too. The more governance; the less likely you’ll see something Oracle has deemed unofficial
s
I take an opposite stance - because it's an ERP and handles money we should write as little code as possible - instead deferring to battle tested libraries when possible and leveraging strong typing to reduce risk. Every line of code we write is a potential bug or exploit. Unless your custom code has exhaustive unit tests and thousands of developers battle testing it in production every day, it's more risky than using a library that does. Similarly, using loose-typed JS will hide many bugs that would be detected by TS. Not using these tools is a serious risk and disservice to the customer, imho.
It reminds me of a project once where I got the client a $1million bonus by just-in-time fixing a pervasive bug caused by code written by them that they would not have if they had used the standard library. In other words, insistence on writing their own code almost cost them $1,000,000.
c
I hope you charged on value and not time.
s
I wish, but alas no 🙂
n
Just a note on this and the original conversation. 😉 Sometimes WebStorm advises me that "Windows Defender" needs an exception adding for the SuiteScript libraries. If that is not set up correctly they appear initially, and then disappear from the project external libraries view. (and you lose the matching you're talking about). It's a complete PITA because sometimes, WS warns you and says it can fix it for you and it works, and other times it doesn't warn you or it says it's fixed and it's not. Sometimes I have to burn my project and create a new one and move over my code just to resolve this. The thing is the warning in WS is in the bottom right of the notifications bar and disappears. So if you load it up and walk off to make a drink / look at some other screen, you can easily miss it.
c
Quick fix - buy a mac 😄
😬 1
s
Or for the same money, buy multiple linux machines