SuiteScript 2.0 search.Type is undefined - netsuite

I am trying something like below:
require(['N/search'],
function(search)
{
var mySearch = search.create({
type : search.Type.FOLDER,
columns : ['internalid'],
filters : [ 'internalid', 'anyof', ID]
});
mySearch.run();
});
I get an error for search.Type.FOLDER that search.Type is undefined and so cannot find FOLDER of undefined
I was able to do a workaround by writing a type as 'folder' that worked, but, why is this enum not defined if it is documented in NetSuite's help.
I tried even logging all keys using Object.keys and the returned array does not contains Type key.
Has anyone tried this or if anyone can point out if something is wrong with my code?

I don't see anything wrong with your code, and I confirmed in my own instance that the module brought in by N/search does not include a Type enum. Including the N/record module does have correctly have the Type enum, so if you want to avoid the magic string 'folder', you could import N/record and use record.Type.FOLDER instead.
It's not ideal, as what you are doing should work, but it seems there must be a bug in the search module where they're not properly returning the Type enum.

Related

How to get the type/interface of an unknown imported function in TypeScript

I've heard that it is bad practice to set an expected type of a variable to any.
However, I don't understand, how I can get a return type of an imported function, which returns an object, which is only used in the library.
As an example, if I would like to use the crypto.createCipheriv() function provided by Node.js, which returns a Cipher object as stated in the docs, I would not known how to give a variable this type.
const variable: ReturnType<crypto.createCipheriv>;

how to check if a variable is Firestore Document Data type?

I am using Typescript and NodeJS for my Google Cloud Function
if I get a document from firestore like this
const result = await db.doc(`events/${eventID}`).get();
const myData = result.data();
then the type of myData is FirebaseFirestore.DocumentData like this
in other part of my code,
I need to check, if a variable has the type of FirebaseFirestore.DocumentData or not using the code below
if ( myVariable instanceof FirebaseFirestore.DocumentData ) {
// do something
}
but I have an error like this
Property 'DocumentData' does not exist on type 'typeof
FirebaseFirestore'
so how to check if my variable is a type of Firestore Document Data?
I see this answer , and it needs to import something so I can access it. how to do something like that for FirebaseFirestore.DocumentData ?
As with your other question you are mixing up Typescript types and JavaScript objects.
FirebaseFirestore.DocumentData refers to a type that is used by the TypeScript compiler as a compile time check. TypeScript compiles down to JavaScript and JavaScript doesn't know about those types during runtime. So the only way to check if the returned data is the Document Data you have to check for the existence of fields or check for undefined.

Test if a property in objectContaining is an Array or undefined

I am using Jest (TypeScript on Node.js) for unit testing and would like to check if a specific property is either an Array or undefined using expect.objectContaining(). This property may or may not exist in the object, hence why I want my test to include both cases.
My initial idea was to use
propertyInQuestion: expect.any(Array || undefined)
inside objectContaining(), but it fails because an Array is expected. When I checked the documentation, it stated that an expected object must be a subset of the received object, so it contains properties that are present in the expected object. So what happens when a property is either present and must be of an Array type or is undefined and therefore not present in the object?
At the moment, test looks something like this
expect(someObject).toEqual(
expect.objectContaining({
propertyInQuestion: expect.any(Array),
something: expect.any(Array),
})
);
and the property I'd like to check is propertyInQuestion, which can either be an Array or undefined.
Any sort of help is appreciated. Thank you!

Missing "types" property of #google-vision npm package

When trying to use the "types" enum of the google-vision package an error is thrown, and no such property exists in the object.
The documentation on how to use is here:
https://cloud.google.com/nodejs/docs/reference/vision/0.19.x/v1.ImageAnnotatorClient#methods
This is the code and error. You can see in the variables section on the left there is no "types" property to the object.
The documentation it states i should access the types of fearture like this:
[{type: vision.types.Feature.Type.FACE_DETECTION},
{type: vision.types.Feature.Type.WEB_DETECTION}]
I believe this is what I have done.
I would appreciate any comments on what the problem may be.
Thanks
Andrew
The nodejs sample code uses strings instead of enums. Can you try using a string instead?

Mongoose schema method not working after select paramter

I have a mongoose model with a method that checks a field and dynamically returns a value, and is called in an HTML template.
This gave me a problem when cleaning up routes to only select fields needed on the page.
After including the select parameter as in Model.find({}, 'select parameter', cb..., this schema method started failing, despite including in the select parameter the property this schema method checks.
Whats up with this, is there a way around it?
The schema method is defined inside thingSchema.methods: { ... ...
and looks for this.thing.length
which is included in the select parameter 'thing, otherThing, thingyThing, thingestThing'
and is called in the html template like thing.getThing(), which will throw error can't find prop length of undefined.
It turns out there is a problem with the string type for the select parameter.
Use the object type instead: {thing:1,otherThing:1,things:1}.

Resources