react-native icon indicating copy to clipboard operation
react-native copied to clipboard

React-Native + Typescript Error

Open costerik opened this issue 6 years ago • 8 comments

Hey guys there is an error when I run yarn tsc

node_modules/@types/reach__router/index.d.ts:14:49 - error TS2304: Cannot find name 'Window'.

14 export type WindowLocation<S = LocationState> = Window['location'] & HLocation<S>;
                                                   ~~~~~~
Found 1 error.

Any suggestion?

costerik avatar Jun 12 '20 06:06 costerik

Same issue, Window shouldn't be present in react-native

jazalizil avatar Jun 22 '20 10:06 jazalizil

I fixed this with a manual declaration:

declare module 'storybook-router' {
  global {
    interface Window {
      location: any;
    }
  }
}

djMax avatar Jun 22 '20 15:06 djMax

@djMax what file did you make the fix in?

Knguyen21 avatar Jul 24 '20 12:07 Knguyen21

I have a third party declaration folder, which I include via tsconfig:

{
  "extends": "../../tsconfig.build.json",

  "compilerOptions": {
    "outDir": "./build"
  },

  "include": [
    "./src/*",
    "../../@types/*"
  ]
}

I have a monorepo, so my config is more complicated, but the key line is including the @types folder (which I made, and which has this declaration in it)

djMax avatar Jul 24 '20 14:07 djMax

@djMax sorry, but i'm still confused. Can you outline the steps you did? Based on what you wrote, I see that you created an @types folder and put the declaration

 {
  "extends": "../../tsconfig.build.json",

  "compilerOptions": {
    "outDir": "./build"
  },

  "include": [
    "./src/*",
    "../../@types/*"
  ]
}

in it, but what did you name the file?
And what kind of file did you put this code

declare module 'storybook-router' {
  global {
    interface Window {
      location: any;
    }
  }
}

did you add a file to .storybook?

Knguyen21 avatar Jul 24 '20 19:07 Knguyen21

These are generic typescript questions... But, it doesn't matter what you name the file, other than ".d.ts" extension, so mine is third-party.d.ts.

djMax avatar Jul 25 '20 01:07 djMax

This seems like an issue with the reach router types. If you're sure this is related to storybook can you provide more details about your dev environment such as the version you have installed and the reach router version in the lock file. It possible that it can be fixed by an update to the reach router dependency on our side that's why I'm asking.

dannyhw avatar Aug 04 '20 16:08 dannyhw

let me know if you want to reopen but I think this is outdated now

dannyhw avatar Jul 14 '23 10:07 dannyhw