@ta-interaktiv/types
v0.4.1
Published
Typescript types for commonly used objects and APIs
Downloads
93
Readme
@ta-interaktiv/types
Use this repository for all commonly used TypeScript interfaces and API definitions.
Installation within the packages
repository
- Add the following line to the peer dependencies in package's
package.json
:"@ta-interaktiv/types": "file:../types",
- Add the following lines to the
references
property array in your package'stsconfig.json
:{ "path": "../types" }
Usage
ArticleId
Interface
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 (
<div>
This article has the ID {articleId}. Also, have this {additionalProp}.
</div>
)
}
The Locale
interface works similar.
Tenants enum
Returns all the possible domain names of our paid meda tenants
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 APIs
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
import { Content } from '@ta-interaktiv/types/lib/feed-prod.unitycms.io/tenant/Content'
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.
Newsnet API Interfaces (Deprecated)
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.
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)
})