Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: difference between any and object without properties? #245

Closed
joffrey-bion opened this issue May 17, 2021 · 5 comments
Closed

Comments

@joffrey-bion
Copy link

In the protocol definitions, I have seen occurrences of both type: "any" and type: "object" without any properties list.

What's the difference? Is it that any can be anything including primitives (effectively any JSON value) but object is limited to only structures with properties (effectively only JSON objects)?

In that case, does an object without properties list represent a type whose properties are unknown/dynamic?

In the typescript definitions, I noticed that most params of type object without properties are represented with the Headers interface, which is basically {[key: string]: string}. This would confirm my guess here. However, some are still translated into TS's any (e.g. PausedEvent.data), which is why I'm asking here.

@TimvdLippe
Copy link
Contributor

As I read the .json file, the "type": "object" denote interfaces. For example,

maps to
export interface KeyframesRule {

The "type": "any" is used to denote values of an interface itself. I don't think there is any occurrence of "type": "object" of a value of an interface, is there?

@joffrey-bion
Copy link
Author

joffrey-bion commented May 18, 2021

I think I might have been unclear here. The general case of "type": "object" indeed represents interfaces, like the one you linked to here. For this purpose, "type": "object" goes along with "properties": [ ... ], which describes the properties of the interface.

In this question, I am specifically talking about places where "type": "object" is used without any "properties": [...] along with it. For instance:

"type": "object"

That's an occurrence of a type object as a parameter of an event. It's not a reference to an existing interface declared as top-level domain type. But it's ok because it has no properties (so we're not in a situation like #244). So I guess what this means here is that it's a JSON object but without details about what properties are available.

The only difference I can imagine with "type": "any" is that I guess any could represent any sort of JSON element (primitives, arrays, objects), while "type": "object" could only represent actual JSON objects ({ ... }).

@TimvdLippe
Copy link
Contributor

Ah I see, I had missed the usage in js_protocol.pdl. I have asked internally for clarification on this.

@joffrey-bion
Copy link
Author

joffrey-bion commented May 18, 2021

No problem, I was also confused when I searched browser_protocol and didn't find my examples anymore :D Took me a moment to realize it was in the other file.

Thanks a lot for asking around!

@caseq
Copy link

caseq commented May 19, 2021

@joffrey-bion, you're reading it right -- "type": "any" implies any type at all, including primitive types such as boolean/numer/string, while "type": "object" implies a JSON object (i.e. a dictionary with string keys and values of "any" type).

@caseq caseq closed this as completed May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants