frenic / csstype

Strict TypeScript and Flow types for style based on MDN data
MIT License
1.7k stars 69 forks source link

Modify property #128

Closed frenic closed 3 years ago

frenic commented 3 years ago

What if I wanted to modify the type definition of a prop, for example "fontWeight"? I tried the following but it's not working. Maybe because of my lack of typescript knowledge.

import * as CSS from 'csstype'

declare module 'csstype' {
  export interface Properties {
    fontWeight: Property.FontWeight | 'medium'
  }
}

Originally posted by @cobalt-medma in https://github.com/frenic/csstype/issues/63#issuecomment-831276507

frenic commented 3 years ago

@cobalt-medma I moved your question to a separate issue because it didn't have anything to do with the original issue.

This one is tricky. I haven't found a way to modify existing properties using module augmentation. But first off; if a value is missing (except for CSS Custom Properties) we need to make sure the MDN data is corrected.

Alternatively you can use type assertion to temporarily solve your issue. Here's an example:


const style: CSS.Properties = {
  ['fontWeight' as any]: 'medium',
};
cobalt-medma commented 3 years ago

@frenic It's not that a type is missing but that I'm using xstyled which has some transformation. If I write 'medium' or 'something' it would replace it with a value defined in my theme. But my theme defined props like medium and light.

frenic commented 3 years ago

In that case I think you should open this question to xstyled