I use command react-native init "name project" then open vscode appear to have error message code. (image)
A type alias is basically a name for any type. Type aliases can be used to represent not only primitives but also object types, union types, tuples and intersections.
You can actually use a type alias to give a name to any type at all, not just an object type. For example, a type alias can name a union type: Note that aliases are only aliases - you cannot use type aliases to create different/distinct “versions” of the same type.
This condition will always return 'false' since the types 'typeof firstName' and 'typeof secondName' have no overlap. You can learn more about them in Symbols reference page. Step one in learning TypeScript: The basic types.
Argument of type '"automatic"' is not assignable to parameter of type 'Options | "auto"'. Argument of type '"automatic"' is not assignable to parameter of type 'Options | "auto"'. There’s one more kind of literal type: boolean literals. There are only two boolean literal types, and as you might guess, they are the types true and false .
Property 'toUpperCase' does not exist on type 'number'. The solution is to narrow the union with code, the same as you would in JavaScript without type annotations. Narrowing occurs when TypeScript can deduce a more specific type for a value based on the structure of the code.
This is what you need to do with VS Code, observe the gif carefully
Steps to resolve error 1. Go to extension 2. Click on more (...) and select Show Built-in extension 3. Search "TypeScript and JavaScript Language Features" - yellow & blue icon 4. Click on Setting icon of extension and select Disable (workspace) 5. Click on Reload / Restart Required
If you are getting this in React Native its probably a known bug in VSCode, that when Google Flow (which competes with MS Typescript) is coded, shows errors erroneously mentioning Typescript.
Your current .js code is supposed to be preprocessed by Flow into another .js file with "proper" js.
So make sure Flow is installed and then disable the Typescript parsing support. Here's the official answer on the Flow installation webpage:
Set javascript.validate.enable option to false or completely disable the built-in TypeScript extension for your project (see gif below)...
Otherwise, you may want to stay as is and just change your code as suggested by C2P1 on March 19, 2018 on the github issue 631
To disable the [js] parser (connected to Typescript),
In VSCode menu: File -> Preferences -> User settings
, (or ctrl+,
) and add the following line
"javascript.validate.enable": false,
This answer was completed after seeing Idan Dagan's answer (Not the accepted answer) here: js 'types' can only be used in a .ts file - Visual Studio Code using @ts-check
And here's an excellent albeit old page about setting up the react-native environment, from Hackernoon. (You also have the VSCode React-native-full plugin)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With