```ts
export function matchSetting(rules: Record<string, string>, name: string): string | null {
  if (typeof name !== 'string' || name === '' || name.includes('*')) {
    throw Error('Invalid name');
  }

  let bestMatch = null;

  for (const selector in rules) {
    const value = rules[selector];
    if (typeof value !== 'string') {
      throw Error('Invalid rule value');
    }

    if (selector === name) {
      return value;
    } else if (selector.endsWith('.*')) {
      const prefix = selector.slice(0, -2);
      if (name.startsWith(prefix)) {
        if (!bestMatch || selector.length > bestMatch.selector.length) {
          bestMatch = { selector, value };
        }
      }
    } else if (selector === '*') {
      bestMatch = { selector, value };
    }
  }

  return bestMatch ? bestMatch.value : null;
}
```