Comments (8)
For Booleans, to save backwards compatibility, a good shape would be:
enum BooleanEnum {
True = "https://schema.org/True",
False = "https://schema.org/False"
}
/** Boolean: True or False. */
export type Boolean = true | false | BooleanEnum;
export const Boolean = {
True: BooleanEnum.True as const,
False: BooleanEnum.False as const,
}
So you can use:
Boolean.True
,Boolean.False
,
as well astrue
andfalse
.
from schema-dts.
Thanks for the suggestions. This is helpful. For each of these, I'm basically curious if these semantics are seen as "canonical" in general. Any data / leads here will be helpful:
For Boolean types, my understanding is that these are expected to be assignable to "https://schema.org/True" and "https://schema.org/False" (from looking at Schema.org examples using Boolean). Do you have an example of true/false JSON primitives being accepted?
For width
/height
-- these are type Distance of QuantitativeValue. My understanding of both those types is that they're meant to encode a value with some unit attached to it. #19 as you mentioned supported using "string" for these values. I.e. "12 m" (or "13px"). Seems contrary to the intent of the schema to make distance potentially unit-less?
Ack on author/contentLocation. I know Person and Place are both accepted the Google Structured Data Testing Tool as stand-ins for {"@type": ..., "name": <string value> }
. My hope was to be slightly opinionated here and allow the equivalent but more verbose version. Does this slow people down in the wild? Curious about your use cases.
from schema-dts.
Do you have an example of true/false JSON primitives being accepted?
See the first example here: https://schema.org/isAccessibleForFree
Seems contrary to the intent of the schema to make distance potentially unit-less?
Good point, maybe ignore my suggestion that number
should be allowed!
My hope was to be slightly opinionated here and allow the equivalent but more verbose version. Does this slow people down in the wild? Curious about your use cases.
That makes sense. I'm fine with that.
Another one to consider: allow thumbnail
to be a string
(URL). Or would you group that with author
/contentLocation
, i.e. require an object?
from schema-dts.
My hope was to be slightly opinionated here and allow the equivalent but more verbose version. Does this slow people down in the wild? Curious about your use cases.
On second thoughts, it seems a shame if the types don't work with the examples provided on https://schema.org/, e.g. https://schema.org/ImageObject uses string
for author
and contentLocation
.
from schema-dts.
Ended up with something slightly different:
/** Boolean: True or False. */
export declare type Boolean = true | false | "https://schema.org/True" | "https://schema.org/False";
export declare const Boolean: {
True: "https://schema.org/True" as const;
False: "https://schema.org/False" as const;
};
This also allows users to assign the strings as-is, in addition to Boolean.True
and Boolean.False
.
from schema-dts.
#47 will fix most of this. Note that, for
Another one to consider: allow
thumbnail
to be astring
(URL). Or would you group that withauthor
/contentLocation
, i.e. require an object?
won't be fixed. As far as I can tell, SDTT complains if ImageObject is declared a string. Let me know if I'm wrong here.
from schema-dts.
@Eyas Thanks for doing that!
As for thumbnail
, here's an example on the official schema website demonstrating thumbnail
as a string
:
https://schema.org/VideoObject
from schema-dts.
Hm. Note that ImageObject doesn't always work as a string, for example:
https://lists.w3.org/Archives/Public/public-schemaorg/2019Nov/0003.html
Structured Data Testing Tool rejects when "logo" is set to a string, requiring an ImageObject set explicitly.
from schema-dts.
Related Issues (20)
- Type errors against Google's recommended Schema JSON-LD's HOT 5
- Bundles to Webpack when not needed HOT 2
- Allow Role to be used for use cases like defining dates HOT 10
- Feature Request: schema-dts-gen --file=my-custom-schema-file.nt HOT 2
- BUG: schema-dts-gen and custom context - prefixes other than "schema" are ignored during generation of code for types HOT 4
- Feature Request: Add safeJsonLdReplacer() from react-schemaorg to schema-dts-gen generated code
- WithContext<T> should be assignable to T HOT 5
- hiringOrganization HOT 3
- Error TS4023 when importing types HOT 5
- Generate types for external schema HOT 10
- Person does not inherit correctly from interfaces PersonLeaf -> PersonBase HOT 10
- Increasing HTML size HOT 1
- Support for Multi-Typed Entities HOT 10
- Installing as dependency (instead of devDependency) makes final bundle big HOT 2
- Add an install option for pending HOT 3
- WithContext: Type '"https://schema.org"' is not assignable to type '"https://schema.org"' HOT 2
- sameAs as an array HOT 2
- Wrong type picked on using WithContext HOT 1
- '@type' as array HOT 3
- Rich Result Text shows "offer" error when using Motorcycle type
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from schema-dts.