Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Docs: use TypeScript and plain JS in examples #495

Closed
layershifter opened this issue Nov 19, 2018 · 1 comment · Fixed by #650
Closed

Docs: use TypeScript and plain JS in examples #495

layershifter opened this issue Nov 19, 2018 · 1 comment · Fixed by #650
Assignees
Labels
vsts Paired with ticket in vsts

Comments

@layershifter
Copy link
Member

Input

  • we want to write examples in TypeScript to get working all TS features and checks
  • we want to show examples to user in JS and TS

Solution

Semantic UI React has a plugin that simply writes sources to a JSON file.

I have an idea about similar solution, but more advanced. We can use babel and babel-preset-typescript to generate following structure:

type ComponentExampleSource = {
  js: {
    children: string,
    shorthand: string,
  },
  ts: {
    children: string,
    shorthand: string,
  },
}

type ComponentExampleSources = {
  [k: string]: ComponentExampleSource
}

This will give us ability to get sources of example very easily and create a toggle with JS and TS in docs. BTW, this will allow us to drop raw-loader 😄

We will need to write a small plugin that will transform imports:

import * as _ from 'lodash'
import * as React from 'react'
// =>
import _ from 'lodash'
import React from 'react'

Quick POC: https://codesandbox.io/s/yv285k54lx

@hughreeling
Copy link
Contributor

Or at least add Typescript specific gotya and examples. For example:

const centered = {
textAlign: 'center',
}

doesn't work
Should be

const centered: ICSSInJSStyle = {
textAlign: 'center',
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
vsts Paired with ticket in vsts
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants