styled-components / polished

A lightweight toolset for writing styles in JavaScript ✨
https://polished.js.org/
MIT License
7.63k stars 209 forks source link

Typescript value vs type reference (v4.0.3) #550

Open jzempel opened 3 years ago

jzempel commented 3 years ago

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/polished@4.0.3/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.

bhough commented 3 years ago

@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.