split-pane-react icon indicating copy to clipboard operation
split-pane-react copied to clipboard

SashContent children and Typescript

Open LindaJuffermans opened this issue 1 year ago • 6 comments

I'm trying to use this in a Next w/Typescript project:

<SashContent className={styles.sashWrapLineActive}>
  <span className={styles.sashWrapLine}></span>
</SashContent>

Typescript complains about the span element:

types.d.ts(60, 5): The expected type comes from property 'children' which is declared here on type 'IntrinsicAttributes & ISashContentProps'

Do I need to add anything to allow the element or is this a bug in split-pane-react? On the interface, I see children is defined as JSX.Element[]

LindaJuffermans avatar Mar 06 '23 10:03 LindaJuffermans

Same here

InTheNooB avatar May 04 '23 14:05 InTheNooB

In my case it was because i was using react-split-pan instead of split-pane-react...

InTheNooB avatar May 04 '23 14:05 InTheNooB

Maybe you need to add sashRender paras like this: https://codesandbox.io/s/split-pane-themes-xmsqtt And u can use the default like this: https://github.com/yyllff/split-pane-react/issues/12#issuecomment-1357527567

RCQE avatar Jun 29 '23 06:06 RCQE

I guess it's a bug in the definition of the children property of ISashContentProps

Instead of declaring it as type JSX.Element[] it should also support other types e.g. a single element.

Using React with Typescript, children is normally defined as being of type ReactNode see e.g. https://blog.logrocket.com/react-children-prop-typescript/

cwellsx avatar Jan 05 '24 05:01 cwellsx

FYI I too get the error in the OP if I try to compile this code using TypeScript.

The code in question is in (and copied from) the themes demo e.g.:

  • https://codesandbox.io/p/sandbox/split-pane-themes-xmsqtt?file=%2Fsrc%2Fdemos%2Fdemo3.jsx

That demo is a *.jsx file not a *.tsx file.

cwellsx avatar Jan 05 '24 21:01 cwellsx

I worked-around this problem by using the normal typescript instead of trying to use a theme, and instead adding some CSS to get something looking like the "line" style.

sashRender={(_, active) => <SashContent active={active} type="vscode"></SashContent>}

and

.split-sash-content.split-sash-content-vscode {
  background-color: rgb(200,200,200);
  width: 2px;
}
.split-sash-content.split-sash-content-vscode.split-sash-content-active {
  width: 100%;
}

cwellsx avatar Jan 06 '24 04:01 cwellsx