polished icon indicating copy to clipboard operation
polished copied to clipboard

Typescript value vs type reference (v4.0.3)

Open jzempel opened this issue 5 years ago • 1 comments

  • polished version: 4.0.3
  • JSS-in_CSS library and version: styled-components 4.4.1
  • Any relevant JS library and version: React 16.13.1

Mixin/Helper/Shorthand Usage

Updated code based on v4 breaking changes.

import exponentialSymbols from 'polished/lib/math/presets/exponentialSymbols';

const squareSize = math(`${size} * 2 / sqrt(2)`, exponentialSymbols);

What You Are Seeing

On tsc compile:

Screen Shot 2020-11-10 at 8 33 15 AM

What You Expected To See

No tsc errors with exponentialSymbols import. I think the fix might be as simple as adding typeof to the function definitions in https://unpkg.com/browse/[email protected]/lib/math/presets/exponentialSymbols.d.ts.

declare const exponentialSymbols: {
  symbols: {
    '!': {
      postfix: {
        f: typeof factorial;
        ...
      };
    };
    '^': {
      infix: {
        f: typeof power;
        ...
      };
    };
    sqrt: {
      func: {
        f: typeof sqrt;
        ...
      };
    };
  };
};

Reproduction

Currently working around by inlining the symbols definition for sqrt. See https://github.com/zendeskgarden/react-components/pull/920/files#diff-e8a3ada410dbb11bc3294a80df7fd05ac795d41d99ffdc21e4597c7787fa7991 for details.

jzempel avatar Nov 10 '20 17:11 jzempel

@jzempel Thank you for bringing this to our attention. We were missing a TS test for this scenario.

Unfortunately, the library we use for generating types for TS is fairly limited and no longer maintained. We are rewriting 5.0 in TS natively, so this will be addressed then. Apologies for the limitation.

bhough avatar Nov 21 '20 15:11 bhough