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

  let bestMatch: [string | null, string | null] = [null, null];

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

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

  return bestMatch[0];
}
```