In Expo 40 - here was how I was able to get it running!
Expo website source without typescript.
Note you'll have to put the files in the assets
directory, and make sure your app.json
specifies all of the needed extensions, mine includes everything: "assetBundlePatterns": ["**/*"],
First, I'll split it into two parts - getting Expo to work, then getting typescript to work.
Expo was simple, but only once I realized it was the issue. I followed the above guide. In summary:
expo install @expo/metro-config
- create a
metro.config.js
and call the push
method with whatever extension you are trying to add, in my case it was md
(markdown):
const { getDefaultConfig } = require('@expo/metro-config');
const defaultConfig = getDefaultConfig(__dirname);
defaultConfig.resolver.assetExts.push('md');
module.exports = defaultConfig;
- Reset cache on expo (shift + r in the terminal window running it, on Mac)
Typescript (4) was documented elsewhere:
- Create a declaration (
*.d.ts
) file, specifying markdown as a valid extension: declare module "*.<SOME_COOL_FILE_EXTENSION>"
- Make sure that file was in one of my
tsconfig.json
root directories (which are listed in the compilationOptions
-> "include"
key).
- Add that file to
typeRoot
under compilationOptions
in tsconfig.json
- import/require the
md
in my component
For me these steps ended up being:
- add a file in
./app/declaration.d.ts
containing just: declare module "*.md"
- My
"include"
had the app
directory in it, and looked like this: "include": ["App.js", "app", "test", "storybook"]
- I added this to
compilationOptions
: "typeRoots":["./app/declaration.d.ts"],
import newborn from './../../../assets/resources/MY_MD_DOC.md'
Tada!