Comments (4)
The error is misleading, but TypeScript is being tripped up by "@context"
and excess property checks.
tl;dr: If this is a top-level object, change the type to WithContext<LocalBusiness>
. Or otherwise drop @context
(you only need a context at the topmost JSON-LD object or graph).
Explanation
TypeScript generally has excess property checks to make sure you're not misspelling something, e.g.:
type A = { x?: string; y?: string; }
const thing: A = {z: string};
while technically thing
is a subtype of A
, this is often a sign of mistake, so TS will warn that z
is wrong.
In schema-dts, @context
is only supplied in WithContext<T>
. Unfortunately, instead of straightforwardly complaining about @context
not being found, TS does it in a very weird way when there's a discriminated union.
from schema-dts.
I think we can close this, but let me know if you have any issues here!
from schema-dts.
@Eyas Thank you!! It feels great to have some type safety on my structured data. Thanks to this library, I found a small error in the existing data.
I wonder if the WithContext
trick could be documented somewhere. I tried Googling my way out of the problem, but I couldn't find any documentation on this error.
from schema-dts.
That's a good point! WithContext
is briefly mentioned in the "Root Context" section of the readme (right under usage), but if you're troubleshooting your failure (especially cryptic sounding errors from TS) then you'll have trouble finding WithContext
as the answer.
Honestly I'm open to feedback. I agree additional documentation is helpful, but I'm not sure what/where. You can always open a PR and fix/add docs as well!
from schema-dts.
Related Issues (20)
- 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
- TS4058: Return type of exported function has or is using name WebSiteLeaf from external module ... but cannot be named HOT 3
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.