Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

typescript-styled-plugin

Microsoft182.5kMITdeprecated0.18.3TypeScript support: included

Deprecated in favor of https://github.com/styled-components/typescript-styled-plugin

TypeScript language service plugin that adds IntelliSense for styled components

TypeScript, styled, styled-components, styled components, css

readme

TypeScript Styled Plugin

❗️ This package has been deprecated in favor of Styled component's fork.

TypeScript server plugin that adds intellisense to styled component css strings

Build Status

Features

  • IntelliSense for CSS property names and values.
  • Syntax error reporting.
  • Quick fixes for misspelled property names.

Usage

This plugin requires TypeScript 2.4 or later. It can provide intellisense in both JavaScript and TypeScript files within any editor that uses TypeScript to power their language features. This includes VS Code, Sublime with the TypeScript plugin, Atom with the TypeScript plugin, Visual Studio, and others.

With VS Code

Just install the VS Code Styled Components extension. This extension adds syntax highlighting and IntelliSense for styled components in JavaScript and TypeScript files.

If you are using a workspace version of TypeScript however, you must manually install the plugin along side the version of TypeScript in your workspace:

npm install --save-dev typescript-styled-plugin typescript

Then add a plugins section to your tsconfig.json or jsconfig.json

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-styled-plugin"
      }
    ]
  }
}

Finally, run the Select TypeScript version command in VS Code to switch to use the workspace version of TypeScript for VS Code's JavaScript and TypeScript language support. You can find more information about managing typescript versions in the VS Code documentation.

With Sublime

This plugin works with the Sublime TypeScript plugin.

First install the plugin and a copy of TypeScript in your workspace:

npm install --save-dev typescript-styled-plugin typescript

And configure Sublime to use the workspace version of TypeScript by setting the typescript_tsdk setting in Sublime:

{
    "typescript_tsdk": "/Users/matb/my-amazing-project/node_modules/typescript/lib"
}

Finally add a plugins section to your tsconfig.json or jsconfig.json and restart Sublime.

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-styled-plugin"
      }
    ]
  }
}

With Atom

This plugin works with the Atom TypeScript plugin.

First install the plugin and a copy of TypeScript in your workspace:

npm install --save-dev typescript-styled-plugin typescript

Then add a plugins section to your tsconfig.json or jsconfig.json and restart Atom.

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-styled-plugin"
      }
    ]
  }
}

To get sytnax highlighting for styled strings in Atom, consider installing the language-babel extension.

With Visual Studio

This plugin works Visual Studio 2017 using the TypeScript 2.5+ SDK.

First install the plugin in your project:

npm install --save-dev typescript-styled-plugin

Then add a plugins section to your tsconfig.json.

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-styled-plugin"
      }
    ]
  }
}

Then reload your project to make sure the plugin has been loaded properly. Note that jsconfig.json projects are currently not supported in VS.

Configuration

Tags

This plugin adds styled component IntelliSense to any template literal tagged with styled, css, injectGlobal, keyframes or createGlobalStyle:

import styled from 'styled-components'

styled.button`
    color: blue;
`

You can enable IntelliSense for other tag names by configuring "tags":

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-styled-plugin",
        "tags": [
          "styled",
          "css",
          "sty"
        ]
      }
    ]
  }
}

Now strings tagged with either styled, css, or sty will have styled component IntelliSense:

import sty from 'styled-components'

sty.button`
    color: blue;
`

Tags also apply to methods on styled components. This is enabled for extend by default:

import sty from 'styled-components'

const BlueButton = sty.button`
    color: blue;
`

const MyFancyBlueButton = BlueButton.extend`
    border: 10px solid hotpink;
`

Linting

To disable error reporting, set "validate": false in the plugin configuration:

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-styled-plugin",
        "validate": false
      }
    ]
  }
}

You can also configure how errors are reported using linter settings.

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-styled-plugin",
        "lint": {
          "vendorPrefix": "error",
          "zeroUnits": "ignore"
        }
      }
    ]
  }
}

The following lint options are supported:

validProperties

["property1", "property2", ....]

List of properties that are treated as valid.

unknownProperties

"ignore" | "warning" | "error"

Should unknown properties show an error or warning? Default is "warning".

compatibleVendorPrefixes

"ignore" | "warning" | "error"

When using a vendor-specific prefix make sure to also include all other vendor-specific properties. Default is "ignore".

vendorPrefix

"ignore" | "warning" | "error"

When using a vendor-specific prefix also include the standard property. Default is "warning".

duplicateProperties

"ignore" | "warning" | "error"

Do not use duplicate style definitions. Default is "ignore".

emptyRules

"ignore" | "warning" | "error"

Do not use empty rulesets. Default is "ignore".

importStatement

"ignore" | "warning" | "error"

Import statements do not load in parallel. Default is "ignore".

boxModel

"ignore" | "warning" | "error"

Do not use width or height when using padding or border. Default is "ignore".

universalSelector

"ignore" | "warning" | "error"

The universal selector (*) is known to be slow. Default is "ignore".

zeroUnits

"ignore" | "warning" | "error"

No unit for zero needed. Default is "ignore".

fontFaceProperties

"ignore" | "warning" | "error"

@font-face rule must define 'src' and 'font-family' properties. Default is "warning".

hexColorLength

"ignore" | "warning" | "error"

Hex colors must consist of three or six hex numbers. Default is "error".

argumentsInColorFunction

"ignore" | "warning" | "error"

Invalid number of parameters. Default is "error".

ieHack

"ignore" | "warning" | "error"

IE hacks are only necessary when supporting IE7 and older. Default is "ignore".

unknownVendorSpecificProperties

"ignore" | "warning" | "error"

Unknown vendor specific property. Default is "ignore".

propertyIgnoredDueToDisplay

"ignore" | "warning" | "error"

Property is ignored due to the display. E.g. with 'display: inline', the width, height, margin-top, margin-bottom, and float properties have no effect. Default is "warning"

important

"ignore" | "warning" | "error"

Avoid using !important. It is an indication that the specificity of the entire CSS has gotten out of control and needs to be refactored. Default is "ignore".

float

"ignore" | "warning" | "error"

Avoid using 'float'. Floats lead to fragile CSS that is easy to break if one aspect of the layout changes. Default is "ignore".

idSelector

"ignore" | "warning" | "error"

Selectors should not contain IDs because these rules are too tightly coupled with the HTML. Default is "ignore".

Emmet in completion list

You can now see your Emmet abbreviations expanded and included in the completion list. An upstream issue with typescript blocks the Emmet entry in the completion list to get updated as you type. So for now you will have to press Ctrl+Space after typing out the abbreviation.

The below settings which are in sync with general Emmet settings in VS Code control the expanded Emmet abbreviations in the auto-completion list.

showExpandedAbbreviation

"always" | "never"

Controls whether or not expanded Emmet abbreviations should show up in the completion list

showSuggestionsAsSnippets

`true` | `false`

If true, then Emmet suggestions will show up as snippets allowing you to order them as per editor.snippetSuggestions setting.

preferences

Preferences used to modify behavior of some actions and resolvers of Emmet.

Contributing

To build the typescript-styled-plugin, you'll need Git and Node.js.

First, fork the typescript-styled-plugin repo and clone your fork:

git clone https://github.com/YOUR_GITHUB_ACCOUNT_NAME/typescript-styled-plugin.git
cd typescript-styled-plugin

Then install dev dependencies:

npm install

The plugin is written in TypeScript. The source code is in the src/ directory with the compiled JavaScript output to the lib/ directory. Kick off a build using the compile script:

npm run compile

switch to e2 to install or update test dependencies:

(cd e2e && npm install)

and then navigate back to the project root and run the end to end tests with the e2e script:

cd ..
npm run e2e

You can submit bug fixes and features through pull requests. To get started, first checkout a new feature branch on your local repo:

git checkout -b my-awesome-new-feature-branch

Make the desired code changes, commit them, and then push the changes up to your forked repository:

git push origin my-awesome-new-feature-branch

Then submit a pull request against the Microsoft typescript-styled-plugin repository.

Please also see our Code of Conduct.

Credits

Code originally forked from: https://github.com/Quramy/ts-graphql-plugin

changelog

Changelog

0.18.3 - April 4, 2023

0.18.2 - December 06, 2021

  • Include completion spans in responses. Thanks @jasonwilliams!
  • Don't trigger completions when opening template tags. Thanks @jasonwilliams!

0.18.1 - August 05, 2021

  • Update emmet. Thanks @jasonwilliams!

0.18.0 - June 03, 2021

  • Enable IntelliSense in keyframes. Thanks @jasonwilliams!

0.17.0 - May 07, 2021

  • Apply in keyframes by default. Thanks @jasonwilliams!

0.16.0 - April 28, 2021

  • Pick up new language service version. Thanks @hantatsang and @jasonwilliams!

0.15.0 - October 16, 2019

  • Pick up new language service version. Thanks @apust!

0.14.0 - February 26, 2019

  • Pick up new language service version.
  • Support for dynamically changing configuration.
  • Only enable plugin for TS 3.0+ in order to support automatically enabling plugin for workspace TS versions.

0.13.0 - November 8, 2018

  • Mark color completions with the 'color' kindModifier. This allows editors to render the color previews inline.
  • Fix more false positive errors.

0.12.0 - October 15, 2018

  • Pick up new decorator library version to fix a possible state corruption error.

0.11.0 - September 11, 2018

  • Fixed some false positive errors when using a placeholder in a contexual selector. Thanks @lukyth!
  • Apply in injectGlobal or createGlobalStyle by default. Thanks @scf4!

0.10.0 - July 10, 2018

  • Add folding support.

0.9.2 - July 9, 2018

  • Remove TS as peerDep.

0.9.1 - July 9, 2018

  • Allow language service to be consumed by other libraries.

0.8.1 - July 2, 2018

  • Fix some false error reports around creative uses of placeholders.

0.8.0 - July 2, 2018

  • Support for emotion style typescript declarations.

0.7.0 - June 25, 2018

  • Picked up new CSS version. Brings improved suggestions and better documentation.

0.6.3 - April 20, 2018

  • Fixed width: ${1}%; incorrectly reported as an error.

0.6.2 - April 18, 2018

  • Fixed case where a placeholder that looked like a mixin was incorrectly reported as an error.

0.6.1 - April 16, 2018

  • Fixed some cases where placeholder usage was incorrectly reported as an error.

0.6.0 - February 16, 2018

  • Added emmet suggestions. Thanks @ramya-rao-a!

0.5.1 - February 13, 2018

  • Small fix for suggestions inside of nested selectors.

0.5.0 - February 12, 2018

  • Add quick fixes for misspelled property names.

0.4.1 - February 12, 2018

  • Fixed false error when placeholder is used as a selector.

0.4.0 - January 16, 2018

  • Fix suggestions inside of nested selectors. Thanks @aczekajski!

0.3.1 - January 11, 2018

  • Cache completion entries so we don't recompute them as often.

0.3.0 - January 9, 2018

  • Added basic support for completion entry details

0.2.2 - November 29, 2017

  • Fix auto import completions not showing up when using plugin with TS 2.6.2+

0.2.1 - November 27, 2017

  • Fix cases where placeholder is followed by a trailing semicolon. Thanks @kingdaro!

0.2.0 - November 9, 2017

  • Do not take runtime dependecy on TypeScript.

0.1.2 — October 24, 2017

  • Fix bug that could cause errors not to be reported when on the last line of a block.

0.1.1 — October 24, 2017

  • Compile to ES5 to support regular Visual Studio

0.1.0

  • Support for nested classes. Thanks @asvetliakov!
  • Support for styled properties, such as MyButton.extend.... Thanks @asvetliakov!
  • Fix a bug that could cause errors to stop being reported.

0.0.5 - September 29, 2017

  • Fix empty value error being showing when using placeholder for value in multiline template strings.

0.0.4 - September 29, 2017

  • Fix multiline strings with placeholders.

0.0.3 - September 29, 2017

  • Initial support for strings with placeholders.

0.0.2 - September 29, 2017

  • Disable empty ruleset lint error by default
  • Fix styled completions showing on character immediately before start of string
  • Supprt css tag by default.
  • Remove a bunch of files from published npm package.

0.0.1 - September 28, 2017

  • Initial release