-
-
Notifications
You must be signed in to change notification settings - Fork 634
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
Add enhanced typings #1287
Add enhanced typings #1287
Conversation
export interface ComponentClass<P = {}> { | ||
new (props?: P, context?: any): Component<P, {}>; | ||
|
||
propTypes?: ValidationMap<P>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inferno does not have propTypes or contextTypes
export type InfernoChildren = string | number | boolean | undefined | VNode | Array<string | number | VNode> | null; | ||
|
||
export interface Props { | ||
children?: InfernoChildren; | ||
ref?: Ref | null; | ||
key?: any; | ||
className?: string; | ||
[k: string]: any; | ||
// [k: string]: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented out code?
packages/inferno/src/global.d.ts
Outdated
React projects that don't include the DOM library need these interfaces to compile. | ||
React Native applications use React, but there is no DOM available. The JavaScript runtime | ||
is ES6/ES2015 only. These definitions allow such projects to compile with only `--lib ES6`. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this for inferno?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remove the reference to global, there are errors with HTMLWebViewElement. Also this would be needed for projects that use Inferno on the server side.
packages/inferno/src/index.ts
Outdated
@@ -33,10 +42,3852 @@ if (process.env.NODE_ENV !== 'production') { | |||
} | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these type declarations could be in its own file ?
FYI, I refactored the event typings to fit more with Inferno and rebased my PR on the current dev branch. I'm pretty sure there will be more cleanup/simplification necessary before this can be merged. I'll keep working on this maybe tomorrow. |
There is issue related to typings: #1295 , Could that be taken care of same time? |
Welp, looks like "tomorrow" turned into "next week..." :P I think this PR is ready for a final review and merge. |
packages/inferno-compat/src/index.ts
Outdated
@@ -275,7 +275,7 @@ class PureComponent<P, S> extends Component<P, S> { | |||
class WrapperComponent<P, S> extends Component<P, S> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can neaten this up by having
interface ContextProps {
context: any;
}
type WrappedComponentProps<OriginalProps> = OriginalProps | ContextProps
class WrappedComponent<P, S> extends Component<WrappedComponentProps<P>, S> {
@as-com What is The status of this PR. We will need to release V5 because of breaking change in Webpack compatibility. Including this there would be nice |
@Havunen This PR is ready for merging, unless you find anything else that needs to be changed. 😄 |
How does this |
Could this issue be solved too in this PR? #1209 |
@@ -42,7 +42,7 @@ export function invariant(condition, format, a?, b?, c?, d?, e?, f?) { | |||
const ARR = []; | |||
|
|||
export const Children = { | |||
forEach(children: any[], fn: Function): void { | |||
forEach(children: any, fn: Function): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typing seems to be more correct with any[]
as before?
You may need to run |
Ok. I think this is good to go then! Lets merge it and go for v5! |
Thank you for your work @as-com |
Objective
This PR adds enhanced typings for JSX as well as a number of other tweaks to enable Inferno to work with TypeScript's strict mode enabled.
Typings were copied from
@types/react
and bashed on until it and an example project compiled. Types and interfaces were modified to fit Inferno's internal types, classes were removed, and unimplemented features were commented out. Please feel free to rearrange/rewrite any of the type definitions I wrote if you have more knowledge of Inferno and/or TypeScript.Closes Issue
It closes issue #686