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
Type errors against Google's recommended Schema JSON-LD's #130
Comments
:( Yeah. https://schema.org/reviewCount says it's an In reality, every Schema.org property is implicitly convertible from a string. But making everything a string can also defeat the purpose of type checking. So right now I've approached a per-type opt-in strategy. Opting in Integer feels... too much? Some discussion previously in #37. HOWEVER, https://devblogs.microsoft.com/typescript/announcing-typescript-4-1-beta/#template-literal-types I wonder if we can require TypeScript 4.1 in the next major release (0.8.x) and define Integer to include any numeric type? Except microsoft/TypeScript#40580 implies this is kind of limited. Open to feedback from the community here. |
Thanks for your reply @Eyas and great insight. I can sympathise with the direction you've taken. I also understand that specification (schema.org) does not imply implementation (Google). That being said, these typings must allow deviation from the official specification in order to appease the major search engines, even if they were to completely become separate. Regarding your idea |
The other thing going on is that schema.org's own examples use strings for these properties. Right now, I'm not as keen to support If we went with such an implementation, what properties would need to be in on list to meet an ergonomic use? I assume:
Let me know if you run into anything else |
Not quite type NumericStirng = `${number}`;
const allowed_1: NumericStirng = '012420932892389.43';
const allowed_2: NumericStirng = '43893';
const not_allowed_1: NumericStirng = '012.4.4';
const not_allowed_2: NumericStirng = '';
const not_allowed_3: NumericStirng = 'abc'; This is more appropriate for the |
Schema.org Numbers, Integers, and Floats support being assigned to strings with the appropriate fromat (e.g. "4394" for Integer). With TypeScript 4.1.0 and beyond, this can be expressed with the `` `${number}` `` type. This pushes the minimum required version for schema-dts from 3.4.0 to 4.1.0, and is thus a breaking change. Note there's a future situation where we would RESTRICT the `Integer` type further; so that only valid integral numbers are assignable to it. This will be another breaking change for another time, when TypeScript can finally represent this. Fixes google#130.
Fixed in v0.10.0 |
Firstly, thank you for this lib and your maintenance of it.
After setting up the typings and using them against Google's recommended Schema markup. In this case I'm seeing errors against
Product
and it's nestedaggregateRating
can you help me understand how to use these typings with Google's recommended versions?Error:
The text was updated successfully, but these errors were encountered: