Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.
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

Description

@layershifter

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

Activity

hughreeling

hughreeling commented on Dec 10, 2018

@hughreeling
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',
}

self-assigned this
on Dec 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

vstsPaired with ticket in vsts

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @hughreeling@layershifter@pkumarie2011

    Issue actions

      Docs: use TypeScript and plain JS in examples · Issue #495 · microsoft/fluent-ui-react