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

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

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