Typescript types for commonly used objects and APIs
npm install @ta-interaktiv/types@ta-interaktiv/typesUse this repository for all commonly used TypeScript interfaces and API definitions.
packages repository1. Add the following line to the peer dependencies in package's package.json:
``json`
"@ta-interaktiv/types": "file:../types",
references
2. Add the following lines to the property array in your package's tsconfig.json:`
json`
{ "path": "../types" }
`typescript jsx
import React from 'react'
import { ArticleId } from '@ta-interaktiv/types'
interface Props extends ArticleId {
additionalProp: string
}
/*
Since the Props interface extends the ArticleId interface, you
have now access to the articleId property.`
*/
function YourComponent({ articleId, additionalProp }: Props) {
return (
This article has the ID {articleId}. Also, have this {additionalProp}.
)
}
The Locale interface works similar.
Returns all the possible domain names of our paid meda tenants
`typescript
import { Tenants, TenantStrings } from '@ta-interaktiv/types'
const bz = Tenants.bernerzeitung // -> 'bernerzeitung'
let domainName: TenantStrings
domainName = 'tagesanzeiger' // works
domainName = 'bilan' // TypeScript will complain
`
Types from the APIs (apart from the old Newsnet API, see below), are not exposed from the top of the package. Instead they try to model the endpoints as close as possible.
#### Examples
`typescript`
import { Content } from '@ta-interaktiv/types/lib/feed-prod.unitycms.io/tenant/Content'
`typescript`
import { SiteInformation } from '@ta-interaktiv/types/lib/admin.publishing.tamedia.ch/admin-api/v1/SiteInformation'
In most cases you won't need to access this information directly, as the functions from @ta-interaktiv/api-access should give you the correct types by default. And you should talk to the API over the api-access package anyway.
These interfaces are here to make working with what the Newsnet API spews out a bit easier. Unfortunately, it is quite impossible to get any reliable documentation from the APIs creator, so we have to reverse-engineer everything – and therefore potentially screwing up occasionally.
`typescript
import { Sites } from '@ta-interaktiv/types'
fetch('https://m.tagesanzeiger.ch/api/sites/default')
.then(response => {
// Check for errors
if (!response.ok) throw new Error('Oh no, there is some error!')
// else parse the answer
return response.json()
})
.then(data => {
const siteInformation: Sites = data.site
// Log the website name (e.g. "Tages-Anzeiger")
console.log(siteInformation.name)
})
``