1

I am getting the Cannot find namespace 'AppStateContext'.ts(2503) on the AppStateContext.Provider line any idea what is causing this it seem it cannot see the variable for some reason.

import React, { useState, createContext } from 'react';

type AppStateValue = {
  darktheme: boolean;
};

const defaultSataeValue: AppStateValue = {
  darktheme: false,
};

export const AppStateContext = createContext(defaultSataeValue);

const AppStateProvider: React.FC = () => {
  return <AppStateContext.Provider value={{}}></AppStateContext.Provider>;
};

// Tsconfig.json
{
  "compilerOptions": {
    "target": "es5",
    "module": "esnext",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": ["src"]
}

enter image description here

1 Answer 1

9

Your file probably has the .ts extension, TSX is only supported in .tsx files. Simply change your extension and you should be good to go.

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.