Skip to content

Instantly share code, notes, and snippets.

@nandorojo
Last active August 20, 2023 05:55
Show Gist options
  • Save nandorojo/d92c8b69bdc02fb207873f38c45f71ab to your computer and use it in GitHub Desktop.
Save nandorojo/d92c8b69bdc02fb207873f38c45f71ab to your computer and use it in GitHub Desktop.
Add Type Safety to Expo config plugins

Typesafe Expo Config Plugins

Add typesafety when applying Config Plugins in your Expo app config.

TypeScript_.TS.Playground.-.An.online.editor.for.exploring.TypeScript.and.JavaScript.-.29.September.2022.mp4

Example app.config.ts file:

// app.config.ts
import { withPodfileProperties } from '@expo/config-plugins'
import { makePlugin } from './make-plugin'

export default {
  plugins: [
    makePlugin(withPodfileProperties, (config) => {
      config.modResults = config.modResults || {}
      config.modResults = {
        ...config.modResults,
        'ios.deploymentTarget': '14.0',
      }
      return config
    })
  ]
}
import { ConfigPlugin } from '@expo/config-plugins'
export const makePlugin = <F extends ConfigPlugin<any>, A extends Parameters<F>[1]>(
f: F,
a: A
): [F, A] => {
return [f, a]
}
@ImBIOS
Copy link

ImBIOS commented Aug 20, 2023

Type '[ConfigPlugin<Mod<Record<string, string>>>, (config: any) => any]' is not assignable to type 'string | [] | [string] | [string, any]'.
  Type '[ConfigPlugin<Mod<Record<string, string>>>, (config: any) => any]' is not assignable to type '[string, any]'.
    Type at position 0 in source is not compatible with type at position 0 in target.
      Type 'ConfigPlugin<Mod<Record<string, string>>>' is not assignable to type 'string'.ts(2322)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment