Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type JSX elements based on createElement function #14729

Open
ivogabe opened this issue Mar 19, 2017 · 33 comments
Open

Type JSX elements based on createElement function #14729

ivogabe opened this issue Mar 19, 2017 · 33 comments
Assignees
Labels
In Discussion Suggestion

Comments

@ivogabe
Copy link
Contributor

@ivogabe ivogabe commented Mar 19, 2017

TypeScript currently uses a JSX namespace to type the props of JSX elements. This is customisable by modifying JSX.IntrinsicElements, JSX.ElementClass. However, the type of an element is always JSX.Element.

Of course more interfaces could be added to the JSX namespace. However, I think that with less effort, the compiler could be made more flexible. I'd propose to check JSX elements based on a (virtual) call to JSX.createElement. For instance, the current behaviour can approximately be written like this:

namespace JSX {
  // intrinsic elements
  function createElement<K extends keyof JSX.IntrinsicElements>(tag: K, props: JSX.IntrinsicElements[K], children: JSX.Element[]): JSX.Element;
  // class and functional components
  function createElement<P>(component: (JSX.ElementClass & { new(): { props: P } }) | ((props: P) => JSX.Element), props: P, children: JSX.Element[]): JSX.Element;
}

Given that function signatures are well customisable with the use of generics for instance, most requests can be implemented this way. For instance, #13890 and #13618 would benefit from this change. Libraries that use JSX, but not on the React-way, will benefit from this too.

Proposed semantics

For a JSX element, a virtual call to JSX.createElement is constructed. It is passed three arguments:

  1. Tag name (string) in case of an intrinsic argument (<div />). Otherwise, the identifier is passed (Foo for <Foo />).
  2. An object containing the props.
  3. An array containing the children.

This should be roughly the same as the JSX transform used in the emitter phase. One notable difference is the following: in case of no properties or no children, an empty object or an empty array should be passed, instead ignoring the argument. This makes it easier to write JSX.createElement for library authors.

Backwards compatibility

For backwards compatibility, one of the following approaches could be taken:

  • Use old logic if JSX.createElement does not exist.
  • If JSX.createElement does not exist, default it to (roughly) the definition above.

Error reporting

When type checking the generated function call, the checker can give error messages like "Argument of type .. " or "Supplied parameters do not match any signature of call target". These messages should be replaced when checking JSX elements.

@RyanCavanaugh
Copy link
Member

@RyanCavanaugh RyanCavanaugh commented Mar 20, 2017

I think this is doable and could potentially cut out a lot of code from the compiler. When we added JSX support we didn't have spread types or keyof / T[k] so this was impossible. Behavior-wise I think this approach would allow all current behavior to be represented with the exception of data- and aria-, which would could special case to not present excess property errors.

The remaining difficulty is just technical - the overload resolution code is hardcoded in a lot of places with the assumption that it's operating over an actual argument list syntax tree rather than some abstract set of parameters.

@niieani
Copy link

@niieani niieani commented Mar 22, 2017

Having this would allow one to utilize the concept of generalized JSX with TS. Currently it seems impossible, because the return type of any JSX expression is always a non-generic JSX.Element.

In fact, given this it would make sense to ditch the whole "JSX" global namespace and just use the declared type of the locally scoped jsxFactory (set in the tsconfig.json), so that the return type of a JSX expression could be different in every file, based on the implementation of the jsxFactory.

@RyanCavanaugh RyanCavanaugh added Help Wanted In Discussion Suggestion and removed Help Wanted labels Mar 22, 2017
@ivogabe
Copy link
Contributor Author

@ivogabe ivogabe commented Apr 4, 2017

I think this is doable and could potentially cut out a lot of code from the compiler. When we added JSX support we didn't have spread types or keyof / T[k] so this was impossible.

That's exactly what I thought!

The remaining difficulty is just technical - the overload resolution code is hardcoded in a lot of places with the assumption that it's operating over an actual argument list syntax tree rather than some abstract set of parameters.

The compiler already handles different kinds of function calls. resolveSignature in checker.ts works with normal call expressions, but also tagged templates and decorators. Those last two don't have an explicit argument list in the source code, so I think that JSX components could be integrated there too? Actually, that function already handles JSX elements for the language service, when used with SFCs.

@niieani That's an interesting use case. I think that it would be useful in a lot of situations, other than the DOM, where some domain specific language is desired.

@niieani
Copy link

@niieani niieani commented Apr 6, 2017

@ivogabe yeah, I especially like the example with ASTs, represented by JSX. So much more readable than declaring plain objects for AST.

@ceymard
Copy link

@ceymard ceymard commented May 15, 2017

I'd like to ping this issue ; could it be possible that the whole jsx mechanic be simply a transform to a function call with its implied checking ?

This would allow for so much flexibility in library creation.

@RyanCavanaugh
Copy link
Member

@RyanCavanaugh RyanCavanaugh commented May 15, 2017

could it be possible that the whole jsx mechanic be simply a transform to a function call with its implied checking ?

No. Two reasons and there may be more:

  • In React properties like data-foo and aria-bar are special, but we'd incorrectly flag these as errors
  • We wouldn't detect excess properties if there was a spread [1]

[1]

interface Point {
    x: number;
    y: number;
}

var m: Point;
var j: Point = { z: 10, ...m }; // Not an error due to spread

@niieani
Copy link

@niieani niieani commented May 16, 2017

@RyanCavanaugh The first could be fixed via other types of constructs that could be added to the language:

WithDomProperties<Point> -- adds typing data-* and aria-* to the type

Second we could think about. Maybe the spreads in JSX would behave differently?

There's probably something we could do. In any case, this would massively simplify the API and allow for custom JSX applications as I've mentioned in the comment above.

@amir-arad
Copy link

@amir-arad amir-arad commented Jun 29, 2017

AFAIK it's not just data-* and area-*, it's *-*.

class Foo extends React.Component<{a:string}>{}

//This works:
<Foo b-3="bar" a="ggg"/>

@joewood
Copy link

@joewood joewood commented Dec 12, 2017

@RyanCavanaugh now that the second point has been fixed, can this be revisited?

interface Point {
    x: number;
    y: number;
}

var m: Point;
var j: Point = { z: 10, ...m }; // NOW ERRORS

@jchitel
Copy link

@jchitel jchitel commented Feb 6, 2018

Another problem to consider here is how to deal with backwards compatibility, particularly around the DefinitelyTyped definitions for React, which would have to be updated to support this.

Existing types that depend on the JSX namespace would no longer work because the compiler wouldn't look there anymore. The most graceful way I can see to handle that would be to modify the React definitions so that the JSX namespace definitions are dependent on (or at least structurally equivalent to) whatever types are used for React.createElement, and deprecate the JSX namespace.

For non-React use cases, this will probably just have to be a breaking change, with a suggested migration pattern. If someone is already using the JSX namespace for typing JSX, all they need to do is add a jsxFactory function (which they probably already have) and tie their JSX types to it.

I agree that having this would improve the flexibility of JSX-in-TS considerably, but the migration for existing code will probably be quite painful.

@mhegazy
Copy link
Contributor

@mhegazy mhegazy commented Feb 13, 2018

should be covered by #21699

gsimone added a commit to pmndrs/drei that referenced this issue Jan 15, 2021
* feat: setup TS for stories

* fix: eslint was ignore .storybook

* feat: add TS to storybook

* refactor: move stories to TS (WIP)

* refactor: move more stories to TS (WIP)

* refactor: src changes for TS move over

I think these were TS problems that were missed.

* fix: ContactShadows story

* refactor: move more stories to TS

* refactor: add MapControls.tsx after raising issues in three

Two errors linked to three.js:
mrdoob/three.js#21058
mrdoob/three.js#21059

* fix: TS errors for passing refs & children

* refactor: add more stories (WIP)

* fix: useContextBridge TS to accept array of children

fixed using DefinitelyTyped/DefinitelyTyped#44572 (comment) because microsoft/TypeScript#14729

* refactor: convert more stories to TS

also useGLTF does not need to declare it's type

* chore: update storybook

* fix: revert useTexture

accidentally committed a WIP change

* refactor: move stories to TS (WIP)

* refactor: revert useGLTF story

* Minor type fixes

* chore: update react-three-fiber to latest

Required for Types

* refactor: move stories to TS

* fix: shaderMaterial on init returns void, not null

* refactor: remove unnecessary type in useFBX

* refactor: type Environment stronger

there was issues with useAsset not understanding it's types....

* Fixes CSB CI (#230)

Co-authored-by: Gianmarco Simone <gianmarcosimone89@gmail.com>
gsimone added a commit to pmndrs/drei that referenced this issue Jan 15, 2021
* feat: setup TS for stories

* fix: eslint was ignore .storybook

* feat: add TS to storybook

* refactor: move stories to TS (WIP)

* refactor: move more stories to TS (WIP)

* refactor: src changes for TS move over

I think these were TS problems that were missed.

* fix: ContactShadows story

* refactor: move more stories to TS

* refactor: add MapControls.tsx after raising issues in three

Two errors linked to three.js:
mrdoob/three.js#21058
mrdoob/three.js#21059

* fix: TS errors for passing refs & children

* refactor: add more stories (WIP)

* fix: useContextBridge TS to accept array of children

fixed using DefinitelyTyped/DefinitelyTyped#44572 (comment) because microsoft/TypeScript#14729

* refactor: convert more stories to TS

also useGLTF does not need to declare it's type

* chore: update storybook

* fix: revert useTexture

accidentally committed a WIP change

* refactor: move stories to TS (WIP)

* refactor: revert useGLTF story

* Minor type fixes

* chore: update react-three-fiber to latest

Required for Types

* refactor: move stories to TS

* fix: shaderMaterial on init returns void, not null

* refactor: remove unnecessary type in useFBX

* refactor: type Environment stronger

there was issues with useAsset not understanding it's types....

* Fixes CSB CI (#230)

Co-authored-by: Gianmarco Simone <gianmarcosimone89@gmail.com>

Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com>
joshuaellis added a commit to pmndrs/drei that referenced this issue Jan 18, 2021
* change: move components into core folder

* feat: add import types web & native

index points to web to avoid breaking changes(?) but also cause that's a good default.

* refactor: rollup so it looks for ts not tsx

* refactor: move Html & Loader to web folder, make folders for native & web

index points to web

* Fixes CSB CI (#230)

* [Feature] move stories to TS (#223) (#231)

* feat: setup TS for stories

* fix: eslint was ignore .storybook

* feat: add TS to storybook

* refactor: move stories to TS (WIP)

* refactor: move more stories to TS (WIP)

* refactor: src changes for TS move over

I think these were TS problems that were missed.

* fix: ContactShadows story

* refactor: move more stories to TS

* refactor: add MapControls.tsx after raising issues in three

Two errors linked to three.js:
mrdoob/three.js#21058
mrdoob/three.js#21059

* fix: TS errors for passing refs & children

* refactor: add more stories (WIP)

* fix: useContextBridge TS to accept array of children

fixed using DefinitelyTyped/DefinitelyTyped#44572 (comment) because microsoft/TypeScript#14729

* refactor: convert more stories to TS

also useGLTF does not need to declare it's type

* chore: update storybook

* fix: revert useTexture

accidentally committed a WIP change

* refactor: move stories to TS (WIP)

* refactor: revert useGLTF story

* Minor type fixes

* chore: update react-three-fiber to latest

Required for Types

* refactor: move stories to TS

* fix: shaderMaterial on init returns void, not null

* refactor: remove unnecessary type in useFBX

* refactor: type Environment stronger

there was issues with useAsset not understanding it's types....

* Fixes CSB CI (#230)

Co-authored-by: Gianmarco Simone <gianmarcosimone89@gmail.com>

Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com>

* 2.2.16

* chore: add templates (#232)

* chore: add react-dom as optional peer depency

if you're using react-native you don't need it.

* docs: update readme

* fix: fix storybook imports that should have been done before

my bad.

Co-authored-by: Gianmarco <gianmarcosimone89@gmail.com>
joshuaellis added a commit to pmndrs/drei that referenced this issue Jan 28, 2021
* [Feature] move stories to TS (#223) (#231)

* feat: setup TS for stories

* fix: eslint was ignore .storybook

* feat: add TS to storybook

* refactor: move stories to TS (WIP)

* refactor: move more stories to TS (WIP)

* refactor: src changes for TS move over

I think these were TS problems that were missed.

* fix: ContactShadows story

* refactor: move more stories to TS

* refactor: add MapControls.tsx after raising issues in three

Two errors linked to three.js:
mrdoob/three.js#21058
mrdoob/three.js#21059

* fix: TS errors for passing refs & children

* refactor: add more stories (WIP)

* fix: useContextBridge TS to accept array of children

fixed using DefinitelyTyped/DefinitelyTyped#44572 (comment) because microsoft/TypeScript#14729

* refactor: convert more stories to TS

also useGLTF does not need to declare it's type

* chore: update storybook

* fix: revert useTexture

accidentally committed a WIP change

* refactor: move stories to TS (WIP)

* refactor: revert useGLTF story

* Minor type fixes

* chore: update react-three-fiber to latest

Required for Types

* refactor: move stories to TS

* fix: shaderMaterial on init returns void, not null

* refactor: remove unnecessary type in useFBX

* refactor: type Environment stronger

there was issues with useAsset not understanding it's types....

* Fixes CSB CI (#230)

Co-authored-by: Gianmarco Simone <gianmarcosimone89@gmail.com>

Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com>

* 2.2.16

* chore: add templates (#232)

* chore: add react-dom as optional peer depency

if you're using react-native you don't need it.

* docs: update readme

* fix: fix storybook imports that should have been done before

* BREAKING CHANGE: refactor internal to solve react-native imports

my bad.

Co-authored-by: Gianmarco <gianmarcosimone89@gmail.com>

* 2.3.0-beta.0

* fix: edit transformOutputPath to remove .ts from files

* 2.3.0-beta.1

* fix: useAnimations ref type & chore: add storybook entry for useAnimations

* Added THREE.Group to useAnimations types

* Small refactor

* Added useAnimations story

* Clean up storybook

* Fix null ref typing on useAnimations

* Forgot to change typing on useAnimations api

* chore: add storybook entry to README

Co-authored-by: Josh Ellis <joshua.ellis18@gmail.com>

* [fix] Blob is undefined when using SSR (#239)

* fix: #233 Blob is undefined in SSR

* refactor: it appears Billboard is fixed

Looks like Typescript does not suck.

* 2.3.0-beta.2

* fix: create polyfill for atob

* 2.3.0-beta.3

* chore: update readme in response to #240

* fix: #242 Frustum has incorrect spelling in softshadows (#243)

* fix: suggestion for fixing #242

* refactor: default should be other way round

* chore: update readme with correct spelling

* 2.3.0-beta.4

* feat: Add MeshoptDecoder support to useGLTF (#246)

* Add MeshoptDecoder support to useGLTF

* chore: move center

Co-authored-by: Josh Ellis <joshua.ellis18@gmail.com>

* 2.3.0-beta.5

* feat: #181 – adding points to line (#247)

* feat: re-create geometry on new points

* refactor: useMemo the geometry instead of useEffect

* 2.3.0-beta.6

* 3.0.0-beta.1

* 3.0.0-beta.2

* feat: update troika with new features (#255)

* 3.0.0-beta.3

* feat: add ability to add custom scene as prop (#256)

* feat: add ability to add custom scene as prop

* docs: update Environment with new feats

* 3.0.0-beta.4

* refactor: shuffle imports for beta

* 3.0.0-beta.5

* docs: clearly specify name of package & old has been deprecated

* BREAKING CHANGE: Upgrade Three.js to r125 (#262)

* chore: update Three.js dependency

* refactor: remove subdivision modifier

* fix: remove use of FaceNormalsHelper as it no longer exists in Three

* fix: update typings for THREE

* fix: update modifiers to work without THREE.Geometry

* docs: update README

* chore: add Three.js peer dependency

* fix: change install instructions to use yarn instead of npm (#265)

* repurpose reflector, make it capable to blur (#260)

* repurpose reflector, make it capable to blur

* refactor: move materials out to reduce noise & fix types

* refactor: merge beta

* fix: add child propType

* refactor: update reflector story & fix children type

* changes

* fix: shuffle types so reflectorProps come from what the material expects

* docs

Co-authored-by: Josh Ellis <joshua.ellis18@gmail.com>

* chore: add workflows to beta release

* BREAKING CHANGE force build

* 3.0.0-beta.6

Co-authored-by: Gianmarco Simone <gianmarcosimone89@gmail.com>
Co-authored-by: Tanner Hartwig <tanner.hartwig57@gmail.com>
Co-authored-by: Matt Rossman <rossman@gatech.edu>
Co-authored-by: Renaud Rohlinger <renaud.rohlinger@gmail.com>
Co-authored-by: Jure Triglav <juretriglav@gmail.com>
Co-authored-by: Jason Bixon <jbixon13@gmail.com>
Co-authored-by: Paul Henschel <drcmda@gmail.com>
@danielo515
Copy link

@danielo515 danielo515 commented Mar 23, 2021

Hey.
I really need to be able to specify which component types are valid, so I can ensure at compile time that my components are being used as I intend them to be used.
Is this really impossible with TS?

@trusktr
Copy link

@trusktr trusktr commented Mar 24, 2021

It is not possible yet.

@danielo515
Copy link

@danielo515 danielo515 commented Mar 24, 2021

So how do you type them when, for example, you need to iterate the children array and access the props? TS will not understand that the children has that props. This is key to produce high quality components that are type safe, is it at least on the roadmap?

superninja0119 pushed a commit to superninja0119/drei that referenced this issue Sep 10, 2021
* feat: setup TS for stories

* fix: eslint was ignore .storybook

* feat: add TS to storybook

* refactor: move stories to TS (WIP)

* refactor: move more stories to TS (WIP)

* refactor: src changes for TS move over

I think these were TS problems that were missed.

* fix: ContactShadows story

* refactor: move more stories to TS

* refactor: add MapControls.tsx after raising issues in three

Two errors linked to three.js:
mrdoob/three.js#21058
mrdoob/three.js#21059

* fix: TS errors for passing refs & children

* refactor: add more stories (WIP)

* fix: useContextBridge TS to accept array of children

fixed using DefinitelyTyped/DefinitelyTyped#44572 (comment) because microsoft/TypeScript#14729

* refactor: convert more stories to TS

also useGLTF does not need to declare it's type

* chore: update storybook

* fix: revert useTexture

accidentally committed a WIP change

* refactor: move stories to TS (WIP)

* refactor: revert useGLTF story

* Minor type fixes

* chore: update react-three-fiber to latest

Required for Types

* refactor: move stories to TS

* fix: shaderMaterial on init returns void, not null

* refactor: remove unnecessary type in useFBX

* refactor: type Environment stronger

there was issues with useAsset not understanding it's types....

* Fixes CSB CI (#230)

Co-authored-by: Gianmarco Simone <gianmarcosimone89@gmail.com>
superninja0119 pushed a commit to superninja0119/drei that referenced this issue Sep 10, 2021
* feat: setup TS for stories

* fix: eslint was ignore .storybook

* feat: add TS to storybook

* refactor: move stories to TS (WIP)

* refactor: move more stories to TS (WIP)

* refactor: src changes for TS move over

I think these were TS problems that were missed.

* fix: ContactShadows story

* refactor: move more stories to TS

* refactor: add MapControls.tsx after raising issues in three

Two errors linked to three.js:
mrdoob/three.js#21058
mrdoob/three.js#21059

* fix: TS errors for passing refs & children

* refactor: add more stories (WIP)

* fix: useContextBridge TS to accept array of children

fixed using DefinitelyTyped/DefinitelyTyped#44572 (comment) because microsoft/TypeScript#14729

* refactor: convert more stories to TS

also useGLTF does not need to declare it's type

* chore: update storybook

* fix: revert useTexture

accidentally committed a WIP change

* refactor: move stories to TS (WIP)

* refactor: revert useGLTF story

* Minor type fixes

* chore: update react-three-fiber to latest

Required for Types

* refactor: move stories to TS

* fix: shaderMaterial on init returns void, not null

* refactor: remove unnecessary type in useFBX

* refactor: type Environment stronger

there was issues with useAsset not understanding it's types....

* Fixes CSB CI (#230)

Co-authored-by: Gianmarco Simone <gianmarcosimone89@gmail.com>

Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com>
superninja0119 pushed a commit to superninja0119/drei that referenced this issue Sep 10, 2021
* change: move components into core folder

* feat: add import types web & native

index points to web to avoid breaking changes(?) but also cause that's a good default.

* refactor: rollup so it looks for ts not tsx

* refactor: move Html & Loader to web folder, make folders for native & web

index points to web

* Fixes CSB CI (#230)

* [Feature] move stories to TS (#223) (#231)

* feat: setup TS for stories

* fix: eslint was ignore .storybook

* feat: add TS to storybook

* refactor: move stories to TS (WIP)

* refactor: move more stories to TS (WIP)

* refactor: src changes for TS move over

I think these were TS problems that were missed.

* fix: ContactShadows story

* refactor: move more stories to TS

* refactor: add MapControls.tsx after raising issues in three

Two errors linked to three.js:
mrdoob/three.js#21058
mrdoob/three.js#21059

* fix: TS errors for passing refs & children

* refactor: add more stories (WIP)

* fix: useContextBridge TS to accept array of children

fixed using DefinitelyTyped/DefinitelyTyped#44572 (comment) because microsoft/TypeScript#14729

* refactor: convert more stories to TS

also useGLTF does not need to declare it's type

* chore: update storybook

* fix: revert useTexture

accidentally committed a WIP change

* refactor: move stories to TS (WIP)

* refactor: revert useGLTF story

* Minor type fixes

* chore: update react-three-fiber to latest

Required for Types

* refactor: move stories to TS

* fix: shaderMaterial on init returns void, not null

* refactor: remove unnecessary type in useFBX

* refactor: type Environment stronger

there was issues with useAsset not understanding it's types....

* Fixes CSB CI (#230)

Co-authored-by: Gianmarco Simone <gianmarcosimone89@gmail.com>

Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com>

* 2.2.16

* chore: add templates (#232)

* chore: add react-dom as optional peer depency

if you're using react-native you don't need it.

* docs: update readme

* fix: fix storybook imports that should have been done before

my bad.

Co-authored-by: Gianmarco <gianmarcosimone89@gmail.com>
superninja0119 pushed a commit to superninja0119/drei that referenced this issue Sep 10, 2021
* [Feature] move stories to TS (#223) (#231)

* feat: setup TS for stories

* fix: eslint was ignore .storybook

* feat: add TS to storybook

* refactor: move stories to TS (WIP)

* refactor: move more stories to TS (WIP)

* refactor: src changes for TS move over

I think these were TS problems that were missed.

* fix: ContactShadows story

* refactor: move more stories to TS

* refactor: add MapControls.tsx after raising issues in three

Two errors linked to three.js:
mrdoob/three.js#21058
mrdoob/three.js#21059

* fix: TS errors for passing refs & children

* refactor: add more stories (WIP)

* fix: useContextBridge TS to accept array of children

fixed using DefinitelyTyped/DefinitelyTyped#44572 (comment) because microsoft/TypeScript#14729

* refactor: convert more stories to TS

also useGLTF does not need to declare it's type

* chore: update storybook

* fix: revert useTexture

accidentally committed a WIP change

* refactor: move stories to TS (WIP)

* refactor: revert useGLTF story

* Minor type fixes

* chore: update react-three-fiber to latest

Required for Types

* refactor: move stories to TS

* fix: shaderMaterial on init returns void, not null

* refactor: remove unnecessary type in useFBX

* refactor: type Environment stronger

there was issues with useAsset not understanding it's types....

* Fixes CSB CI (#230)

Co-authored-by: Gianmarco Simone <gianmarcosimone89@gmail.com>

Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com>

* 2.2.16

* chore: add templates (#232)

* chore: add react-dom as optional peer depency

if you're using react-native you don't need it.

* docs: update readme

* fix: fix storybook imports that should have been done before

* BREAKING CHANGE: refactor internal to solve react-native imports

my bad.

Co-authored-by: Gianmarco <gianmarcosimone89@gmail.com>

* 2.3.0-beta.0

* fix: edit transformOutputPath to remove .ts from files

* 2.3.0-beta.1

* fix: useAnimations ref type & chore: add storybook entry for useAnimations

* Added THREE.Group to useAnimations types

* Small refactor

* Added useAnimations story

* Clean up storybook

* Fix null ref typing on useAnimations

* Forgot to change typing on useAnimations api

* chore: add storybook entry to README

Co-authored-by: Josh Ellis <joshua.ellis18@gmail.com>

* [fix] Blob is undefined when using SSR (#239)

* fix: #233 Blob is undefined in SSR

* refactor: it appears Billboard is fixed

Looks like Typescript does not suck.

* 2.3.0-beta.2

* fix: create polyfill for atob

* 2.3.0-beta.3

* chore: update readme in response to #240

* fix: #242 Frustum has incorrect spelling in softshadows (#243)

* fix: suggestion for fixing #242

* refactor: default should be other way round

* chore: update readme with correct spelling

* 2.3.0-beta.4

* feat: Add MeshoptDecoder support to useGLTF (#246)

* Add MeshoptDecoder support to useGLTF

* chore: move center

Co-authored-by: Josh Ellis <joshua.ellis18@gmail.com>

* 2.3.0-beta.5

* feat: #181 – adding points to line (#247)

* feat: re-create geometry on new points

* refactor: useMemo the geometry instead of useEffect

* 2.3.0-beta.6

* 3.0.0-beta.1

* 3.0.0-beta.2

* feat: update troika with new features (#255)

* 3.0.0-beta.3

* feat: add ability to add custom scene as prop (#256)

* feat: add ability to add custom scene as prop

* docs: update Environment with new feats

* 3.0.0-beta.4

* refactor: shuffle imports for beta

* 3.0.0-beta.5

* docs: clearly specify name of package & old has been deprecated

* BREAKING CHANGE: Upgrade Three.js to r125 (#262)

* chore: update Three.js dependency

* refactor: remove subdivision modifier

* fix: remove use of FaceNormalsHelper as it no longer exists in Three

* fix: update typings for THREE

* fix: update modifiers to work without THREE.Geometry

* docs: update README

* chore: add Three.js peer dependency

* fix: change install instructions to use yarn instead of npm (#265)

* repurpose reflector, make it capable to blur (#260)

* repurpose reflector, make it capable to blur

* refactor: move materials out to reduce noise & fix types

* refactor: merge beta

* fix: add child propType

* refactor: update reflector story & fix children type

* changes

* fix: shuffle types so reflectorProps come from what the material expects

* docs

Co-authored-by: Josh Ellis <joshua.ellis18@gmail.com>

* chore: add workflows to beta release

* BREAKING CHANGE force build

* 3.0.0-beta.6

Co-authored-by: Gianmarco Simone <gianmarcosimone89@gmail.com>
Co-authored-by: Tanner Hartwig <tanner.hartwig57@gmail.com>
Co-authored-by: Matt Rossman <rossman@gatech.edu>
Co-authored-by: Renaud Rohlinger <renaud.rohlinger@gmail.com>
Co-authored-by: Jure Triglav <juretriglav@gmail.com>
Co-authored-by: Jason Bixon <jbixon13@gmail.com>
Co-authored-by: Paul Henschel <drcmda@gmail.com>
@WilliamPeralta

This comment has been minimized.

@trusktr
Copy link

@trusktr trusktr commented Dec 4, 2021

@WilliamPeralta This is not a help channel for JSX component generics. This topic is specifically about the return type of JSX expressions.

I would kindly recommend to delete the post so it isn't distracting, and ask in the appropriate channels (StackOverflow, Discord, etc). You'll get way better help that way.

@polkovnikov-ph
Copy link

@polkovnikov-ph polkovnikov-ph commented Dec 6, 2021

@trusktr
Copy link

@trusktr trusktr commented Dec 8, 2021

I'm all for proper types everywhere, but this issue is about the return types. Once those are in place, this opens room for the generics to be improved.

@RyanCavanaugh As you fear the performance of JSX return types, what about a compromise? Either:

  • enable with an option that defaults to disabled?
  • allow return types only for top level result of a JSX expression so at least something like const div = <div>...</div> regardless of what children the div has.

At least allow us to try the feature in a nightly release and see if it does as poorly as you say. Let us measure it!

@weswigham
Copy link
Member

@weswigham weswigham commented Dec 8, 2021

We kinda did with experimental builds, that's why we know the perf is so bad.

@trusktr
Copy link

@trusktr trusktr commented Dec 8, 2021

Is it worse than nested function calls like h('div', h('p'))?

@weswigham
Copy link
Member

@weswigham weswigham commented Dec 8, 2021

No but yes. No, it's pretty much that exactly (slight note: class/function components are essentially two calls of cost per tag, rather than one), yes, because people don't chain generic functions 100 levels deep in practice (convention simply dictates you use a temporary variable after a few levels of nesting), but do chain jsx tags 100 levels deep.

@niieani
Copy link

@niieani niieani commented Dec 16, 2021

@weswigham would it much of a burden for your team if this were to land behind a flag? Most uses might not need generic JSX, but there are plenty of niche uses that would greatly benefit from this, and 100-level deep nesting of any kind can (and should) be avoided in well crafted code anyway.

@trusktr
Copy link

@trusktr trusktr commented Dec 18, 2021

What about return types, without inference of generics?

@ConnorJamesLow
Copy link

@ConnorJamesLow ConnorJamesLow commented Feb 18, 2022

@RyanCavanaugh As you fear the performance of JSX return types, what about a compromise? Either:

  • enable with an option that defaults to disabled?
  • allow return types only for top level result of a JSX expression so at least something like const div = <div>...</div> regardless of what children the div has.

I'm voting for that second option.

@flying-sheep
Copy link

@flying-sheep flying-sheep commented Jun 16, 2022

Any idea how to get JSX typing per file when using jsx: "react-jsx"?

Before I could just use #22207:

things.ts

namespace mything {
    export namespace JSX {
        type Element = ...
    }
}
export function mything(...) {...}

app.ts

/** @jsx mything */
import { mything } from './things'

const a = <a/>

What can I do now?

/edit: figured it out:

jsx-runtime.ts

export namespace JSX {
    type Element = ...
}
export function jsx(...) {...}

app.ts

/** @jsxImportSource . */

const a = <a/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Suggestion
Projects
None yet
Development

Successfully merging a pull request may close this issue.