The project has continued to improve, validating a broader and more complex subset of Schema.org, improving type-checking performance, and eliminating the runtime bundle entirely. Many of these improvements were only fully understood due to feedback and reports from the community. Today, schema-dts receives more than 100k downloads/week on NPM. These users have helped validate and harden the library over the past few years.
Here are some of the highlighted improvement since the last announcement:
0kb Bundle Runtime SizeThe library is now entirely type only. Previously, convenience enums were generated in .js files, but improved TypeScript completions mean that this is no longer necessary.
RolesA Role in Schema.org is a special kind of relationship that can apply to any property. schema-dts did not previously understand the special nature of Roles, but it now does.
For example, the following code is now fully validated by schema-dts:
Graphs & IDsWhen you have cyclical structured data, it can be helpful to encode it in a JSON-LD "@graph".
JSON-LD can encode a "@graph", representing a series of nodes with "@id" values. Nodes can reference each other simply by ID. For example, here is a cyclical graph showing the "member" relationship used with its inverse "memberOf" relationship:
Numbers as StringsSchema.org long supported using string values to represent Floats, Numbers, and Integers. Thanks to TypeScript’s template literal types introduced in 4.1.0, schema-dts now can type check numeric strings anywhere a Float, Integer, or Number is expected.
Works better with ReactWe also provide a helper library, react-schemaorg, which makes embedding JSON-LD in react easier than ever. While we previously only supported embedding JSON-LD directly into the page, the library now supports utility libraries like react-helmet and Next.js’s next/head.
For example, here is how you can inject JSON-LD into your Next.js component:
I hope you’re excited to try out these new features! As of 1.0, I’m confident the library is stable enough for breaking changes to be few and far between.
If you’re passionate about structured data, please join the conversation on GitHub!
By Eyas Sharaiha, Geo Engineering and Open Source schema-dts Project