1

This is rather odd. I am using visual studio code, having set a react-native with typescript (react-native + nativebase + typescript). While intellisense and type checking works in general, I am facing some troubles with jsx intellisense, code suggestions do not appear for any jsx props.

What I mean is that usually when you tape ctrl+space in a jsx element, vs code displays available props.

enter image description here

This does not works. In the above example the suggestions offered are not the available props of this jsx element <Content>. The consequence is that errors in props listing are not picked up by compiler. For example this code:

enter image description here

is not flagged as an error even though the prop foo does not exists in the definition of the Content component. It has not been defined no where. This is the first time it appears in the code. Yet compiler does not flag it as error.

Typescript is supposed to make javascript typed and pick compile time error.

Here is my tsconfig.json:

{
    "compilerOptions": {
        "target": "es6",
        "allowJs": true,
        "jsx": "react",        
        "rootDir": "modules",
        "sourceMap": true,
        "noImplicitAny": false,     
    },    
    "filesGlob": [        
        "modules/**/*.ts",
        "modules/**/*.tsx",
        "typings/**/*.d.ts"
    ],    
    "exclude": [
        "node_modules"        
    ]
}

Also typescript is properly set in visual studio code as shown on the task bar:

enter image description here

You can see that Typescript with react is set. Also typings are properly referenced in my tsx file:

/// <reference path="../typings/index.d.ts" />

import * as React from 'react';
import { View, Text } from 'react-native';

So how can I get typescript to properly suggest props on jsx elements with ctrl + space and more seriously why is typescript not detecting an error when I use props not defined for a given component? Is it somethings with typings I don't get or is there a setting in the tsconfig.json?

Thank you for your valuable help.

1 Answer 1

3

For any one having a similar problem, I solved my own issue by bringing types in my project by using npm @types (e.g npm install @types/react ) instead of typings or tds.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.