1

My problem is that I'm using an old type declaration package (@types/expo). So that's why I need to update some part of it. I created a new typing file like this. (./typings/expo/index.d.ts)

import * as expo from 'expo';

declare module 'expo' {
  var Icon: any;
  var SplashScreen: any;

  export interface AppLoadingProps {
    startAsync?: () => Promise<void[]>;
  }
}

Some parts were started to work but also I started to get this error:

[ts] Subsequent property declarations must have the same type. 
Property 'startAsync' must be of type '(() => Promise<void>) | undefined', 
but here has type '(() => Promise<void[]>) | undefined'

I searched it on google and typescript forums but It doesn't have any meaningful answer for this. Is it possible to update the interface that has same props? Or do I need to wait until the company updates its package on definitelyTyped?

my tsconfig.json file;

{
  "compilerOptions": {
    "target": "ES2017",
    "module": "es2015",
    "lib": [ /* Specify library files to be included in the compilation. */
      "es2017",
      "dom"
    ],
    "jsx": "react-native",
    "importHelpers": true,
    "strict": true,
    "noImplicitAny": true,
    "strictFunctionTypes": true,
    "noImplicitThis": true,
    "moduleResolution": "node",
    "typeRoots": [ /* List of folders to include type definitions from. */
      "./typings",
      "./node_modules/@types"
    ],
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "noEmitHelpers": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "forceConsistentCasingInFileNames": true,
    "outDir": "build/dist"
  },
  "exclude": [
    "build",
    "node_modules"
  ],
  "types": [
    "typePatches"
  ]
}
the_bluescreen
  • 3,126
  • 2
  • 18
  • 31

1 Answers1

3

If you need to overwrite an existing property declaration to change the type, you'll need to fork the @types/expo types.

The easiest way is probably to copy the index.d.ts file into your typings directory and uninstall the original @types/expo package. Or you can use a tool such as Braid (disclosure: I am a Braid contributor) to import the types/expo/index.d.ts file directly from the DefinitelyTyped repository; this has the advantage that it's easy to merge upstream updates with your own modifications, but this may not matter to you if DefinitelyTyped is going to be updated soon anyway.

Either way, you have the option to adjust your baseUrl and paths options so that module resolution finds your index.d.ts file or to create a package.json for your modified @types/expo package and register it as a dependency in your main package.json using a relative path.

Matt McCutchen
  • 28,856
  • 2
  • 68
  • 75
  • 1
    Thanks! Unfortunately, as you said, there is no easy way to avoid from this. I think it's one of the hardest parts on the typescript. – the_bluescreen Sep 28 '18 at 12:27