TS error using a function to customise defaults with the default unit plugin
- Dominant language
- JavaScript
- Stars
- 7.1k
- Forks
- 386
- PR merge metrics
- No merged PRs in 30d
Description
__Expected behavior:__
Use the 'jss-plugin-default-unit' to override default units for numeric values in combination with TypeScript.
__Describe the bug:__
The plugin itself doesn't appear to have any issues but I am receiving TypeScript related errors in my IDE when using a function to define an option for the plugin.
```javascript
const options = {
width: val => `${val / 2}px`
}
jss.use(defaultUnit(options));
```
Source: https://cssinjs.org/jss-plugin-default-unit/?v=v10.5.0#customizing-defaults
I'm not sure if the following is the cause but the two definitions of the **Options** type do not seem to match:
- [index.js](https://github.com/cssinjs/jss/blob/94c8f6c7e5eee7ce04c31ea2f7e318a5d5b2a082/packages/jss-plugin-default-unit/src/index.js#L5)
- [index.d.ts](https://github.com/cssinjs/jss/blob/94c8f6c7e5eee7ce04c31ea2f7e318a5d5b2a082/packages/jss-plugin-default-unit/src/index.d.ts#L3)
__Codesandbox:__
N/A
__Versions:__
- react-jss: 10.5.0
- typescript: 4.0.3
- OS: Linux
Contributor guide
Research direction
Start by comparing the Options definitions in packages/jss-plugin-default-unit/src/index.js and packages/jss-plugin-default-unit/src/index.d.ts, then reproduce the TypeScript error with the function-based configuration shown in the issue. Done means the type definition matches the implementation and accepts the documented customization example without IDE errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- developer-experience, frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100