```typescript
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: { selector: string; value: string } | null = null;

  for (const [selector, value] of Object.entries(rules)) {
    if (typeof value !== 'string') {
      throw new Error('Invalid rule value');
    }

    if (selector === name) {
      bestMatch = { selector, value };
      break;
    }

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

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