1const formatToList = (items: string[]) => items.map((key) => `- ${key}`).join('\n');
2
3export default function validatePathConfig(config: any, root = true) {
4  const validKeys = ['initialRouteName', 'screens', '_route'];
5
6  if (!root) {
7    validKeys.push('path', 'exact', 'stringify', 'parse');
8  }
9
10  const invalidKeys = Object.keys(config).filter((key) => !validKeys.includes(key));
11
12  if (invalidKeys.length) {
13    throw new Error(
14      `Found invalid properties in the configuration:\n${formatToList(
15        invalidKeys
16      )}\n\nDid you forget to specify them under a 'screens' property?\n\nYou can only specify the following properties:\n${formatToList(
17        validKeys
18      )}\n\nSee https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration.`
19    );
20  }
21
22  if (config.screens) {
23    Object.entries(config.screens).forEach(([_, value]) => {
24      if (typeof value !== 'string') {
25        validatePathConfig(value, false);
26      }
27    });
28  }
29}
30