Hello there,
Kinda new to React, trying to delve a bit into Contexts, however the aforementioned method refuses to exist.
import * as React from "react";
export const UrlEditContext = React.createContext(new UrlViewItem());
This is really all the code I've got on this. This happens both with React 16.4.1 and 16.3.2. Other React libraries I have:
react-dom 16.0.0
react-hot-loader 3.0.0-beta.7 (came with the project created with Visual Studio)
react-router-dom 4.1.1
Typescript's version's 2.4.1.
Anyone has any idea why would I receive the aforementioned error? Google and SO have literally (yes, literally) nothing on the topic.
Thanks,
Huggy
React does not ship its own type definitions, so typescript uses community provided types for it, and yours are out of date. If you're using npm
for package management, you'll need to do:
npm install @types/react@latest
That sounds like a TypeScript error, not a React one. If you search for "does not exist on type" you'll find those errors are coming from TypeScript.
I don't know how to fix this鈥攜ou probably need to update TS's React definitions?
@gaearon Why are you even closing this? Your comment is not helpful whatsoever. I'm pretty sure I know what the "does not exist on type" message means, the problem is I have no idea how to solve it in the context of... React. So, by all means, it's a React-related issue.
I'm sorry if my reply was frustrating. What I'm trying to say is that neither of React's maintainers are TypeScript users, so we can't help you with error messages coming from TypeScript. You are welcome to reach out to TypeScript community forums to ask this. If you were not using TypeScript, you wouldn't see this message鈥擨 assume it was your choice.
Specifically, my understanding is that when you use any library (not just React) in TypeScript, you need to install "typings" (which instruct TypeScript about what a library can do). We don't maintain React typings, somebody else does. The typings you're using are probably outdated. You can probably update them to make TypeScript "see" the new APIs. However, nobody who maintains the React repository is using TypeScript, and we can't advise you as to how to update your typings. If you ask about this on a TypeScript forum or discussion board I bet you'll get a very prompt response.
Note React does not require you to use TypeScript. It is up to individual developers to make that choice.
Cheers!
As to why I'm closing this鈥攚e're using the issue tracker for bug reports and feature requests in React. This is neither. We try to respond to questions when we can, but in this case we're not the right people to answer your question.
We maintain a list of community resources. Some of these might have other TypeScript users, so check them out: https://reactjs.org/community/support.html
Hope it helps!
@gaearon It has nothing to do with being frustrating. It has to do with being useless. nmain's answer solved the problem (cheers mate), so obviously there are some people here, who can help. At least let us have a discussion.
Now please, close away.
@Rufix
Most helpful comment
@Rufix