GithubHelp home page GithubHelp logo

ThingBase is not exported about schema-dts HOT 3 CLOSED

google avatar google commented on May 12, 2024
ThingBase is not exported

from schema-dts.

Comments (3)

Eyas avatar Eyas commented on May 12, 2024 1

I wrote up an explanation here about the structure of the type system, but basically, we have something like:

declare type ThingBase = {
    "additionalType"?: URL | URL[];
    "alternateName"?: Text | Text[];
   // ...
};

// This is conceptually true but in practice, it is inlined:
export declare type ThingLeaf = {
    "@type": "Thing";
} & ThingBase;

export declare type Thing = ThingLeaf | Action | CreativeWork | Event | Intangible | MedicalEntity | Organization | Person | Place | Product /* | ... */;

So Thing itself is not just ThingLeaf, but any subsequent child type. The discriminated unions progress recursively to cover all Schema.org types. e.g.

export declare type Organization = OrganizationLeaf | Airline | Consortium | Corporation | EducationalOrganization | FundingScheme | GovernmentOrganization | LibrarySystem | LocalBusiness | MedicalOrganization | NewsMediaOrganization | NGO | PerformingGroup | Project | SportsOrganization | WorkersUnion;

... and so on.

Under the current type system, Person is part of Thing's union, and thus it extends it.

You can try it out with WithContext, which is supplied by schema-dts and you can import it. It's written as such:

export declare type WithContext<T extends Thing> = T & {
    "@context": "https://schema.org";
};

With that, you can write things like:

import { Person, WithContext } from "schema-dts";

const t: WithContext<Person> = {
  "@context": "https://schema.org",
  "@type": "Person", // "Patient" also works here
  "name": "happy"
};

from schema-dts.

Eyas avatar Eyas commented on May 12, 2024

#28 suggested another use-case where something that looks like this.

My general concern with exporting intermediate types is just that it ties up future development. Right now the API boundary is just the final types (Thing, Person, etc.) and everything in between can change in a breaking way.

As schema-dts matures, I'll be more and more comfortable doing this. Worth looking at this now.

I'm curious, though, why not just use Thing here? It seems like it should just work if WithId was defined as:

export type WithId<T extends Thing> = T & Identified;

That's what we do when we define WithContext right now.

from schema-dts.

rosskevin avatar rosskevin commented on May 12, 2024

But for example Person and Organization do not extend Thing...so how could that be correct?

from schema-dts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.