Extend Type Declarations on TS 3.x

Let’s say you started to work on the fantastic idea. You decided to use typescript and some fancy popular plugins. Then you prepared everything as you want and the project was ready to go. You started to create some components and added them to your page. Everything looks perfect, right? Then you tried to compile the typescript code but BOOM.. you are getting some errors. You checked the all documentation, blogs, forums. Also, you created an issue on GitHub to inform. Everything must work appropriately because all plugin documentations say everything is correct. However, our wonderful friend, typescript, gives an error. Then you realized the type definition of the plugin that you use is old.

If you also get similar stories on typescript, You are in the correct post right now. I searched this problem everywhere but I couldn’t perfect/clean answer for this. So this is my fix for this kind of problems.

Let’s say you are using expo v30, but expo type definition is v27.

- Let’s create Typings folder on your project root.
- Then create another folder as Expo.
- Create a file as index.d.ts inside of Expo.
- Import the old module
- Create new ones

Example;

import * as expo from 'expo'; // import your module to extenddeclare module 'expo' { // create new module    // add your new stuff    export var Icon: any;    export var SplashScreen: any;}

So that’s all. In this way, you can extend or change the module as you want. Then you can send these changes to DefinitelyTyped repo for updating that package type definition.

Written by

The Guy who can write code, manage projects, talk with people, play drums and love blizzard games

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store