Skip to content

Exported scss variables are undefined in typescript #19622

@marek-aguita

Description

@marek-aguita

🐞 Bug report

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

Description

I'm trying to reuse scss variables also in typescript code of the components, but they don't get imported as I'd expect.
Following some tutorials it should be able this way:

  • in styles.scss:

$color: "red";

:export { color: $color; }

  • in styles.scss.d.ts:

export interface Styles { color: string; }

export const styles: Styles;

export default styles;

  • in app.component.ts:

import styles from "../styles.scss";

When I log styles.color, it should say 'red', but it's undefined. However, logging the whole styles variable logs the whole scss :export rule in a form of a string: :export{color:"red"}

🔬 Minimal Reproduction

Open StackBlitz and read what console says.

🌍 Your Environment


Angular CLI: 11.0.4
Node: 12.18.3
OS: win32 x64

Angular: 11.0.4
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
... service-worker
Ivy Workspace: Yes

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.1002.0
@angular-devkit/build-angular      0.1100.4
@angular-devkit/core               10.2.0
@angular-devkit/schematics         11.0.4
@angular/cdk                       11.0.2
@angular/flex-layout               11.0.0-beta.33
@angular/material                  11.0.2
@angular/material-moment-adapter   11.0.2
@schematics/angular                11.0.4
@schematics/update                 0.1100.4
ng-packagr                         11.0.3
rxjs                               6.6.3
typescript                         4.0.5

(The environment is slightly different than the one in StackBlitz I've provided, but the behavior is the same in both my real project and there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions