#Component type

13 messages · Page 1 of 1 (latest)

fluid wraith
#

On the documentation I saw this example :

import { type Component } from "solid-js";

const MyTsComponent(): Component = () => {
  return (
    <div>
      <h1>This is a TypeScript component</h1>
    </div>
  );
}

export default MyTsComponent;

It should not be const MyTsComponent = (): Component => { ? Maybe it is a reserved syntax handled by the solid transpilator ?

(sorry if there are some english errors)

earnest latch
#

Ah that should be

import { type Component } from "solid-js";

const MyTsComponent: Component = () => {
  return (
    <div>
      <h1>This is a TypeScript component</h1>
    </div>
  );
}

export default MyTsComponent;
fluid wraith
#

Ok but what is the différence between
const MyTsComponent: Component = () and const MyTsComponent = (): Component ?

earnest latch
#

The second isn't valid

#

Oh actually no

fluid wraith
#

It is specific to solid or typescript compliant ?

earnest latch
#

const MyTsComponent: Component means 'this function is a component', const MyTsComponent = (): Component means 'this function returns a component'

#

but const MyTsComponent(): Component = () isn't valid typescript and the docs need to be updated

earnest latch
fluid wraith
#

I will search more further, I didn't pay attention but it was not the ts documentation

#

Sorry for that

grand maple
#

this: const MyTsComponent() is definitely wrong and not supported in Solid in any way... Definitely a typo.

can you create an issue or make a PR to fix or give us a url of where you found this ?