aphrodite icon indicating copy to clipboard operation
aphrodite copied to clipboard

Stylesheet.create does not support strict TypeScript type checking or intellisense

Open rpggio opened this issue 4 years ago • 3 comments

CSSProperties type does not support strict typing. It allows any property name to be used for a style. This prevents type checking and intellisense for Stylesheet.create. It appears this is due to CSSPropertiesLossy in the type.

Example: https://codesandbox.io/s/aphrodite-no-type-checking-itwip?file=/src/index.ts

const styles1 = StyleSheet.create({
  blue: {
    backgroundColor: "lightblue",
    // no strict typing
    murgin: "5px"
  }
});

rpggio avatar May 16 '20 20:05 rpggio

I find this is very annoying as well, in addition the browser simply ignores any invalid property, so that manual errors are not detected.

However, I think its intended to be like this, since not all CSS properties are declared in CSSProperties type (eg userSelect), and in order to support custom selector handlers.

zhenwenc avatar May 25 '20 02:05 zhenwenc

I think I did something related to this at Flexport. @dmnd can you check flow-typed-overrides for aphrodite?

zgotsch avatar May 28 '20 00:05 zgotsch

I had the same issue with emotion, and I believe it has to do with the pseudo or attribute selectors. https://github.com/emotion-js/emotion/issues/1888 Ideally we would need to have those declared under a nest property so it can be correctly typed.

zanona avatar Jun 06 '20 09:06 zanona