linkeddata / rdflib.js

Linked Data API for JavaScript
http://linkeddata.github.io/rdflib.js/doc/
Other
564 stars 143 forks source link

Fixed typing error #511

Open jaxoncreed opened 3 years ago

jaxoncreed commented 3 years ago

Other Test and Linter Fixes:

jaxoncreed commented 3 years ago

At least as far as the typings are concerned, options.data is string | undefined, but jsonString is string | undefined | null. All this does is handle the case where jsonString is null.

jaxoncreed commented 3 years ago

@bourgeoa. I looked into it a bit more. options.data is allowed to be undefined as defined here https://github.com/linkeddata/rdflib.js/blob/main/src/fetcher.ts#L187. It's optional, so undefined is allowed. Do you think it shouldn't be optional?

jeff-zucker commented 3 years ago

So it is a question of whether we should let the user create an invalid JSON-LD file. If we say || undefined, we are saying - go ahead create an empty JSON-LD file, you'lll be sorry later, but you asked for it. I we say || {} we are creating something that a later GET with accept=json-ld will not fail on.

jeff-zucker commented 3 years ago

I guess my tendency would be to go ahead and supply the {}.

jeff-zucker commented 3 years ago

The intent of the user's request is "create an empty JSON-LD resource". And BTW I mean jsonString || "{}"; - that will create an empty JSON-LD resource.