Why exactly "IDataObject" and how to work with it?

This might be a stupid question. I see a lot of somethingApiCall() methods in all the nodes, and all of them take an IDataObject type as - for example - query string parameter.

Now as far as I can see this is just an ordinary object with keys limited to strings, right? (ref TS docs).

now I have two questions:

  • am I right? And is the limitation “just” to be sure to always have string keys?
  • If (!) I’m right, I think I understand why the following snippet does not work, but I don’t know how to make it work … . any help appreciated :slight_smile:
const qs: IDataObject = (httpMethod == 'GET')
    ? this.getNodeParameter('queryOptions', 0) as object
    : {};

# error message: 
# Type 'object' is not assignable to type 'IDataObject'.
# Index signature is missing in type '{}'.

thanks in advance! Axel.

It seems this is the solution (it didn’t work on first try, I swear!!):

const qs: IDataObject = (httpMethod == 'GET')
    ? this.getNodeParameter('queryOptions', 0) as IDataObject
    : {};

Since getNodeParameter may return a wide range of types given the wide range of possible parameters, we often cast its return value to help with type-checking. Ideally, in the future we could implement overloads to allow the type-checker to infer the return types for the most frequently used args.