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

Produce JSX Typings file #686

Closed
LukeSheard opened this issue Jan 8, 2017 · 17 comments
Closed

Produce JSX Typings file #686

LukeSheard opened this issue Jan 8, 2017 · 17 comments

Comments

@LukeSheard
Copy link
Contributor

There have been questions and issues raised about our typescript definition files (#592 , #596, #609, #681) as well as questions on Slack.

We should refactor our definition files to include a globals.d.ts which should be internal to Inferno, and then also have namespace and module definitions for each Inferno module. We can then wrap these up in a inferno.d.ts typings file which we export with inferno as a package.

This is probably going to mean writing wrapper scripts and automating more build steps which can be included in #685.

@prabhjots
Copy link

The whole JXS experience inside typescript could be improved by providing better type definitions as explained here
https://www.typescriptlang.org/docs/handbook/jsx.html

We need to add the following to the inferno.d.ts file

declare module 'inferno' {
	.... // some other stuff 

	global {
            export namespace JSX {
                 interface ElementAttributesProperty {
                     props; // specify the property name to use
                 }
           }
	}
}

Also it would be a good idea to provide a different d.ts file for strongly typing the standard dom components.
Please have a look at this gist for a starting point
https://gist.github.com/prabhjots/271be2d9df5f2880ea5ec73e80fdbf00

@SimonMeskens
Copy link

I think the JSX namespace also needs this:

export namespace JSX {
   type Element = VNode;
            
   interface IntrinsicElements {
      ...
   }

This will type the return type of elem() correctly I think.

@pspeter3
Copy link
Collaborator

@LukeSheard I'd be happy to help with this if possible.

@Havunen
Copy link
Member

Havunen commented Mar 4, 2017

What still needs to be done regarding this task?

@Aleksion
Copy link

Aleksion commented Mar 7, 2017

I don't know if it's me doing something wrong, but I hit a few issues when trying to use the Inferno typings in an isomorphic project.

The issue is that the typings assume the importing inferno-component and/or inferno-create-element result in an object with a default export.

However, when typescript is used with module:commonjs, the node version of those components are used and they do NOT contain a default export resulting in the following error:

class Test extends inferno_component_1.default {
                                      ^

TypeError: Class extends value undefined is not a constructor or null

The easy way to ignore this, would be to simply do: const Component = require("inferno-component"), however, typescript doesn't allow extending classes with objects of type "any".

It seems the current typings simply doesn't work with module "commonjs", which is a requirement for running it properly on a server.

Unless I'm missing something?

@Havunen
Copy link
Member

Havunen commented Mar 7, 2017

@Aleksion is this 1.3.0.-rc.10 or 1.2.2? If it is 1.3 try commenting out "jsnext:main" in all installed inferno package.json's

@Aleksion
Copy link

Aleksion commented Mar 7, 2017

@Havunen - I was using 1.3.0-rc.10
Commenting out jsnext:main did nothing to alleviate the issue. However, running 1.2.2 does work.

The problems I have with that though is that the interfaces are defined Globally - meaning Props clash with my own Props interfaces. I do see why they are, when you worked under the constraints of a single typings file. But it's naturally much less of a problem than it not working at all.

could the reason for it working in 1.2.2 be that you're doing the following in the component files:

module.exports = require('inferno/dist/inferno-component.node');
module.exports.default = module.exports;

thus making sure that whether it's resolved by commonjs or es2015 module loaders, it will always get the right code (rather than relying it the babel, typescript, webpack, node implementation loading the right one)

@Havunen
Copy link
Member

Havunen commented Mar 7, 2017

ping @longlho any idea regarding this?

@longlho
Copy link
Member

longlho commented Mar 7, 2017

yeah it seems like rollup UMD packaging by itself is not enough to satisfy all the use cases. rollup isn't particularly forgiving to non-ES6 modules so we might have to bring back the wrapper file

@thomas-jeepe
Copy link

Any updates on typescript jsx support?

@longlho
Copy link
Member

longlho commented Jun 13, 2017 via email

@abirmingham
Copy link

Is there any workaround for type-checking TSX element properties in the meantime? See #1121. Losing type-checking on a slice of the code-base is pretty painful.

@deamme
Copy link
Member

deamme commented Sep 19, 2017

Please look at this one by @rendall https://gist.github.com/rendall/cdd23c962c88fac3dbd9322cc2b09d58

@rendall rendall mentioned this issue Sep 19, 2017
@rendall
Copy link

rendall commented Sep 26, 2017

Would anyone like to form or participate in a working group to hammer this out? If so, please let me know here or direct message. The gist that @deamme referenced above works to resolve basic Inferno TSX conflicts, but conflict with supplemental libraries like inferno-router remain.

@SimonMeskens
Copy link

I'd be willing to help with typings. I don't have a lot of time, but I have a lot of knowledge about TypeScript if that helps.

@LukeSheard LukeSheard changed the title Produce High Quality Typescript Definition File Produce JSX Typings file Dec 19, 2017
@LukeSheard
Copy link
Contributor Author

Happy to take a PR for the JSX. I think we can easily integrate it into our existing build process for the type definitions.

@Havunen
Copy link
Member

Havunen commented Mar 17, 2018

V5 is released. This is fixed there

@Havunen Havunen closed this as completed Mar 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests