Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property is missing in type error

I am having an issue with working through a demo React project. Most of the issues stem from me trying to implement it in Typescript where they are using Javascript. This gist is my app.tsx file.

https://gist.github.com/jjuel/59eed01cccca0a7b4f486181f2a14c6c

When I run this I get errors pertaining to the interface.

ERROR in ./app/app.tsx (38,17): error TS2324: Property 'humans' is missing in type 'IntrinsicAttributes & IntrinsicClassAttributes & AppProps & { children?: ReactElement |...'.

ERROR in ./app/app.tsx (38,17): error TS2324: Property 'stores' is missing in type 'IntrinsicAttributes & IntrinsicClassAttributes & AppProps & { children?: ReactElement |...'. webpack: bundle is now VALID.

I have no idea what is going on with this. Does anyone know what my issue could be? Thanks!

like image 813
j5juice Avatar asked Oct 07 '16 02:10

j5juice


People also ask

Is missing the following properties from type type?

The error "Type is missing the following properties from type" occurs when the type we assign to a variable is missing some of the properties the actual type of the variable expects. To solve the error, make sure to specify all of the required properties on the object.

Is missing the following properties from type react?

The React. js error "Type is missing the following properties from type" occurs when we don't pass any props to a component, or don't pass it all of the props it requires. To solve the error, make sure to provide all of the props that are required in the component. Here is an example of how the error occurs.

Does not exist on type?

The "Property does not exist on type '{}'" error occurs when we try to access or set a property that is not contained in the object's type. To solve the error, type the object properties explicitly or use a type with variable key names.

What is never type in TypeScript?

Never is a new type in TypeScript that denotes values that will never be encountered. Example 1: The null can be assigned to void but null cannot be assigned to never type variables, nor can any other type be assigned including any.


1 Answers

You have the following interface :

interface AppProps {
    humans: any;
    stores: any;
}

Which is you saying that App must be passed in humans and stores. However you are initializing it as <App /> in ReactDOM.render(<App />, document.getElementById('main')); without the properties. This is TypeScript providing you with errors about what you said was the intented use. It's an error like having a function with arguments but calling it without passing any.

Fix

Perhaps these properties are optional for you? If so declare it as such:

interface AppProps {
    humans?: any;
    stores?: any;
}

Otherwise provide them e.g. <App humans={123} stores={123} /> (sample instances of humans and stores).

like image 62
basarat Avatar answered Oct 06 '22 18:10

basarat