Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript ambient type information #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mike-north
Copy link

@mike-north mike-north commented Dec 30, 2017

Requires

Because this is an 'extension of ember' kind of addon (often used without being explicitly imported), consumers will need to do one of two things in order to take advantage of this type information.

A. Indicate that this type information is to be included

tsconfig.json
{
  "compilerOptions": {
      "types": [
         "ember-cli-meta-tags"
       ]
  }
}

B. Import the entry point for this addon from somewhere in their project

app/app.ts
import Application from '@ember/application';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';
import Resolver from './resolver';
// ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ 
import 'ember-cli-meta-tags';

const App = Application.extend({ ... });

After doing either (A) or (B), type-checking will

  • Accurately represent that there's a head-tags service with a collectHeadTags() function on it
  • Accurately represent that the head-data service has a headTags property on it
  • Accurately represent that Routes can now have a headTags property, containing either the array of tags or a function that returns the array

A "tag" is represented as an object having a type and tagId property, an an attrs property defined by an optional generic (by default, an any). This allows developers to define their own specific constraints on top of this

import { HeadTag } from 'ember-cli-meta-tags';

type TwitterCardTag = HeadTag<'meta', {name: string, content: string}>;

// <meta name='twitter:card' content='video' />
let twCardTypeTag: TwitterCardTag = {
  type: 'meta',
  tagId: 'card-type',
  attrs: {
    name: 'twitter:card',
    content: 'video'
  }
}

@josemarluedke
Copy link
Contributor

Is there any intension in moving TypeScript types here further?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants