Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

['type aliases' can only be used in a .ts file]

I use command react-native init "name project" then open vscode appear to have error message code. (image)

enter image description here

like image 454
thana Avatar asked Feb 18 '18 13:02

thana


People also ask

What are type aliases in JavaScript?

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.

Can a type alias be used to name an object type?

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.

Which condition will always return false in typescript?

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.

Which arguments are not assignable to the parameter of type'auto'?

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 .

How do I use touppercase in typescript?

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.


Video Answer


2 Answers

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 

like image 79
ishandutta2007 Avatar answered Sep 20 '22 17:09

ishandutta2007


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)

like image 32
pashute Avatar answered Sep 22 '22 17:09

pashute