google / google/schema-dts

primitive string type disallows picking types from Organization

Open
#50 4 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.2k
Forks
57
PR merge metrics
No merged PRs in 30d

Description

I have built some helper methods to help assemble instances in our common patterns. With the recent introduction of #47, and the fact that none of the `Base` types are exposed (related: https://github.com/google/schema-dts/issues/29#issuecomment-523173992), I no longer have a way to access/reuse the types of the properties within `OrganizationBase` model.

With the latest release including #47, I get:

```
error TS2339: Property 'image' does not exist on type 'Organization'.

5 image: SchemaOrganizationNoRef['image'] | Identified
```

e.g.

```ts
import { Organization as SchemaOrganizationNoRef } from 'schema-dts'
import { Identified } from './Identified'

interface Reffed {
image: SchemaOrganizationNoRef['image'] | Identified

/**
* URL of a logo that is representative of the organization.
*
* Additional image guidelines:
*
* The image must be 112x112px, at minimum.
* The image URL must be crawlable and indexable.
* The image must be in .jpg, .png, or. gif format.
*/
logo: SchemaOrganizationNoRef['logo'] | Identified
}

/**
* Allow given properties to be refs
*/
type SchemaOrganization = Omit & Reffed

interface Required {
address: SchemaOrganizationNoRef['address']
legalName: SchemaOrganizationNoRef['legalName']
name: SchemaOrganizationNoRef['name']
/**
* URL of the organization eg. https://google.com
*/
url: SchemaOrganizationNoRef['url']
}

/**
* Declare our `Organization` as a stricter set of properties
*
* @see https://schema.org/Organization
*/
export type Organization = Omit & Required & Identified

export const buildOrganization = (
o: Omit,
uniqueName = 'organization',
): Organization => ({
// '@context': 'https://schema.org',
'@id': `${o.url}/#${uniqueName}`,
'@type': 'Organization',
...o,
})
```

for completeness:

```ts

export interface Identified {
/**
* preferably url e.g. https://alienfast.com/#organization
*/
'@id': string
}

export function ref(i: I): Identified {
return { '@id': i['@id'] }
}
```

How should I be referencing the declared type of something like `Organization['image']`?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.