score:2
this question is the typescript equivalent of various types of javascript questions that pop up every now and then where the developer confuses passing a function by reference with calling said function in situ whereby just passing its return value.
you are actually calling, i.e. executing, the line generator by doing linegenerator(data)
. as you can see from the api docs and the type definitions this will return either a string or null:
export interface line<datum> {
(data: datum[]): string | null;
//...
}
this does not match the signature of the .attr() method, though, which in this case expects a function to be passed as the second argument.
export interface selection<gelement extends basetype, datum, pelement extends basetype, pdatum> {
//...
attr(name: string, value: valuefn<gelement, datum, string | number | boolean | null>): this;
//...
}
the solution is to pass the generator to .attr()
without executing it:
.attr('d', linegenerator)
the generator will then be executed by the inner workings of .attr()
being passed the data bound to the selection. that, in turn, will return the path definition string for the d
attribute of the path.
Source: stackoverflow.com
Related Query
- Argument of type 'string | null' is not assignable to parameter of type 'ValueFn<SVGPathElement, Datum[], string | number | boolean | null>'
- ReactJS Typescript Argument of type '{ keyPrefix: string; }' is not assignable to parameter of type string
- How to fix the error argument of type string or undefined is not assignable to parameter of type string using typescript and react?
- How to fix error argument of type undefined is not assignable to parameter of type 'string or () => string usng typescript and react?
- React Typescript - Argument of type is not assignable to parameter of type
- Argument of type 'HTMLElement | null' is not assignable to parameter of type 'Element'. Type 'null' is not assignable to type 'Element'.ts(2345)
- Argument of type 'unknown' is not assignable to parameter of type '{}'
- Argument of type 'Element' is not assignable to parameter of type 'ReactElement<any>
- react usestate hooks error: argument of type 'yyy' is not assignable to parameter of type 'setstateaction<xx>'
- getting error : Argument of type '() => () => boolean' is not assignable to parameter of type 'EffectCallback'
- Typescript React/Redux : Argument of type 'typeof MyClass' is not assignable to parameter of type 'ComponentType<...'
- React with Typescript: Argument of type 'never[]' is not assignable to parameter of type 'StateProperties | (() => StateProperties)'
- Argument of type '"MY_EVENTS_LOAD"' is not assignable to parameter of type 'TakeableChannel<unknown>' in yeild takeLatest
- React TypeScript: Argument is not assignable to parameter of type 'never'
- Argument of type 'string' is not assignable to parameter of type '`${string}` | `${string}.${string}` | `${string}.${number}`'
- Argument of type '(dispatch: Dispatch) => void' is not assignable to parameter of type 'AnyAction'
- Argument of type partial is not assignable to parameter of type
- Argument of type 'Date | null' is not assignable to parameter of type 'SetStateAction<Date>'
- React Typescript: Argument of type '{ [x: number]: any; }' is not assignable to parameter of type
- Argument of type 'number' is not assignable to parameter of type 'never' in array.includes()
- Argument of type '() => () => Promise<void>' is not assignable to parameter of type 'EffectCallback'
- Getting an error Argument of type 'unknown' is not assignable to parameter of type 'Error | null'
- Redux Toolkit - Argument of type 'AsyncThunkAction<>' is not assignable to parameter of type 'AnyAction'
- React js Typescript Argument of type 'string' is not assignable to parameter of type 'SetStateAction<number>'
- Argument of type 'Element[]' is not assignable to parameter of type 'Element'
- Redux - createStore. Argument of type is not assignable to parameter of type 'DeepPartial<any>'
- Argument of type 'AsyncThunkAction<any, void, {}>' is not assignable to parameter of type 'AnyAction'
- TS2345: Argument of type 'ReactNode' is not assignable to parameter of type 'ReactElement'
- Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string'
- Argument of type 'typeof test' is not assignable to parameter of type 'Component<{ children?: ReactNode; } & DispatchProp<any>>'
More Query from same tag
- In React audio tag not working, instead it just displays the link
- export const functionName props undefined when using redux
- Display React Bootstrap's Modal when you press a button
- Conditional rendering of HTML elements in React?
- React socket io client emitting twice to node server
- How to send specific API data from one component to another called within React Component in react
- How to check if data is returned from api?
- Updating props in Higher Order Components
- How to get mui Chip value before delete on Autocomplete freeSolo?
- How to User Login With Wordpress using React Native
- I'm try to send a request to the server
- Upload file is only sending text to e-mail from React Form
- How to test api calls within redux-saga
- ReactJs Updating state of similar property value
- React jsx variable to element inline style not working
- change brand details by selecting options javascript
- React : Link to PDF which is in my project folder
- How to create a JSDoc of ref when using React.fowardRef and useImperativeHandle?
- How to make React (Router) point to WP backend file
- How can I properly add headers in my axios post request, post route works in postman but not when using axios
- How to access the catch all route after ajax call failed while not changing URL with react-router
- How to list items from object array by category and only render components based on which category was last iterated
- How to make responsive my react component
- Typescript and Reducer function with multiple payload options
- Grouping variable number of elements with React / JSX
- React, pass data from child to parent with props
- React useState hook isn't updating the state
- Conditionally rendering a component
- Babel not outputting flow comments
- <fieldset> breaking onChange in React form