diff --git a/types/css-modules/css-modules-tests.ts b/types/css-modules/css-modules-tests.ts new file mode 100644 index 0000000000..5876f5beae --- /dev/null +++ b/types/css-modules/css-modules-tests.ts @@ -0,0 +1,21 @@ +import styles from './main.sass'; +import * as classNames from 'classnames'; + +class App { + private theme: string; + constructor(theme: string) { + this.theme = theme; + } + + render() { + // as a style tag (using webpack's css-loader) + const tpl = `
`; + // or as scoped unique classes, also latest typescript versions allow prop access using dot like styles.darkUI instead of styles['darkUI'] + return ` +
+
+ `; + } +} diff --git a/types/css-modules/index.d.ts b/types/css-modules/index.d.ts new file mode 100644 index 0000000000..7d7bd52abd --- /dev/null +++ b/types/css-modules/index.d.ts @@ -0,0 +1,38 @@ +// Type definitions for css-modules 1.0 +// Project: https://github.com/css-modules/css-modules +// Definitions by: NeekSandhu +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +interface Stringifyable { + /** + * Stringifies the imported stylesheet for use with inline style tags + */ + toString(): string; +} +interface SelectorNode { + /** + * Returns the specific selector from imported stylesheet as string + */ + [key: string]: string; +} + +declare module '*.css' { + const styles: SelectorNode & Stringifyable; + export default styles; +} + +declare module '*.scss' { + const styles: SelectorNode & Stringifyable; + export default styles; +} + +declare module '*.sass' { + const styles: SelectorNode & Stringifyable; + export default styles; +} + +declare module '*.less' { + const styles: SelectorNode & Stringifyable; + export default styles; +} diff --git a/types/css-modules/tsconfig.json b/types/css-modules/tsconfig.json new file mode 100644 index 0000000000..aff10df5a6 --- /dev/null +++ b/types/css-modules/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "css-modules-tests.ts" + ] +} \ No newline at end of file diff --git a/types/css-modules/tslint.json b/types/css-modules/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/css-modules/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }