```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 result: [string, string] | 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 prefix = selector.slice(0, -2);
      if (name.startsWith(prefix)) {
        if (!result || prefix.length > result[0].length) {
          result = [prefix, value];
        }
      }
    } else if (selector === '*') {
      if (!result) {
        result = ['*', value];
      }
    }
  }

  return result ? result[1] : null;
}
```