@ta-interaktiv/types
TypeScript icon, indicating that this package has built-in type declarations

0.4.1 • Public • Published

@ta-interaktiv/types

Use this repository for all commonly used TypeScript interfaces and API definitions.

Installation within the packages repository

  1. Add the following line to the peer dependencies in package's package.json:
    "@ta-interaktiv/types": "file:../types",
  2. Add the following lines to the references property array in your package's tsconfig.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)
  })

Readme

Keywords

Package Sidebar

Install

npm i @ta-interaktiv/types

Weekly Downloads

134

Version

0.4.1

License

ISC

Unpacked Size

20.1 kB

Total Files

20

Last publish

Collaborators

  • s1co
  • dariush-mehdiaraghi
  • mrdz_tx
  • mathiaslutz
  • sebaa