-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Labels
Description
This code:
import React from 'react';
type ObjectType = {
usedDirectly: string;
usedFromArray: string;
};
export class UseDirectly extends React.Component {
props: {
object: ObjectType;
}
render() {
console.log(this.props.object.usedDirectly);
return null;
}
}
export class UseFromArray extends React.Component {
props: {
objects: Array<ObjectType>;
}
render() {
console.log(this.props.objects[0].usedFromArray);
return null;
}
}triggers this warning:
5:18 error 'object.usedFromArray' PropType is defined but prop is never used react/no-unused-prop-types
Though strangely, this code encounters no errors:
import React from 'react';
type ObjectType = {
usedDirectly: string;
usedFromArray: string;
};
export class UseDirectly extends React.Component {
props: {
object: any;
}
render() {
console.log(this.props.object.usedDirectly);
return null;
}
}
export class UseFromArray extends React.Component {
props: {
objects: Array<ObjectType>;
}
render() {
console.log(this.props.objects[0].usedFromArray);
return null;
}
}So you don't have to go hunting/searching, the only difference between them is the object: ObjectType vsobject: any. (Not sure why changing UseDirectly would affect the used-ness of usedFromArray field.)
guyellis