Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion types/react/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ declare namespace React {
*/
context: unknown;

constructor(props: Readonly<P> | P);
constructor(props: P);
/**
* @deprecated
* @see {@link https://legacy.reactjs.org/docs/legacy-context.html React Docs}
Expand Down
15 changes: 15 additions & 0 deletions types/react/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ declare const container: Element;
}
}
class BetterPropsAndStateChecksComponent extends React.Component<Props, State, Snapshot> {
constructor(props: Props) {
super(props);
// This should ideally error since `props` should not be mutated, but it doesn't.
props.foo = 2;
// @ts-expect-error
this.props = { type: "foo" };
}

render() {
return null;
}
Expand Down Expand Up @@ -117,6 +125,13 @@ declare const container: Element;
};
}
}

class InferredConstructorProps extends React.Component<{ value: string }> {
// @ts-expect-error ts(7006) Ideally, this would infer the props type from the type parameter but has implicit any.
constructor(props) {
super(props);
}
}
}

class ModernComponent extends React.Component<Props, State, Snapshot>
Expand Down
2 changes: 1 addition & 1 deletion types/react/ts5.0/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ declare namespace React {
*/
context: unknown;

constructor(props: Readonly<P> | P);
constructor(props: P);
/**
* @deprecated
* @see {@link https://legacy.reactjs.org/docs/legacy-context.html React Docs}
Expand Down
15 changes: 15 additions & 0 deletions types/react/ts5.0/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ declare const container: Element;
}
}
class BetterPropsAndStateChecksComponent extends React.Component<Props, State, Snapshot> {
constructor(props: Props) {
super(props);
// This should ideally error since `props` should not be mutated, but it doesn't.
props.foo = 2;
// @ts-expect-error
this.props = { type: "foo" };
}

render() {
return null;
}
Expand Down Expand Up @@ -117,6 +125,13 @@ declare const container: Element;
};
}
}

class InferredConstructorProps extends React.Component<{ value: string }> {
// @ts-expect-error ts(7006) Ideally, this would infer the props type from the type parameter but has implicit any.
constructor(props) {
super(props);
}
}
}

class ModernComponent extends React.Component<Props, State, Snapshot>
Expand Down