Don't use type as a variable name as it is a TS keyword.

This commit is contained in:
Bauke 2022-10-18 22:21:55 +02:00
parent e2d233f8d6
commit f261052331
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
7 changed files with 16 additions and 16 deletions

View File

@ -4,12 +4,12 @@ export const redirectTypes = ['hostname', 'simple'] as const;
export type MatcherType = typeof matcherTypes[number];
export type RedirectType = typeof redirectTypes[number];
export function narrowMatchType(type: string): type is MatcherType {
return matcherTypes.includes(type as MatcherType);
export function narrowMatchType(value: string): value is MatcherType {
return matcherTypes.includes(value as MatcherType);
}
export function narrowRedirectType(type: string): type is RedirectType {
return redirectTypes.includes(type as RedirectType);
export function narrowRedirectType(value: string): value is RedirectType {
return redirectTypes.includes(value as RedirectType);
}
export type Matcher = {
@ -18,7 +18,7 @@ export type Matcher = {
};
export type RedirectParameters = {
type: RedirectType;
redirectType: RedirectType;
};
export abstract class Redirect<P extends RedirectParameters> {

View File

@ -10,13 +10,13 @@ export type Redirects = HostnameRedirect | SimpleRedirect;
export function parseRedirect<P extends Redirects['parameters']>(
parameters: P,
): Redirects | undefined {
const type = parameters?.type;
const redirectType = parameters?.redirectType;
if (type === 'hostname') {
if (redirectType === 'hostname') {
return new HostnameRedirect(parameters);
}
if (type === 'simple') {
if (redirectType === 'simple') {
return new SimpleRedirect(parameters);
}
}

View File

@ -2,7 +2,7 @@ import {Redirect} from './base.js';
export type HostnameParameters = {
hostname: string;
type: 'hostname';
redirectType: 'hostname';
};
export class HostnameRedirect extends Redirect<HostnameParameters> {

View File

@ -2,7 +2,7 @@ import {Redirect} from './base.js';
export type SimpleParameters = {
target: string;
type: 'simple';
redirectType: 'simple';
};
export class SimpleRedirect extends Redirect<SimpleParameters> {

View File

@ -19,14 +19,14 @@ const hostnameParameters: HostnameRedirect['parameters'] = {
hostname: 'example.org',
matcherType: 'hostname',
toMatch: 'example.com',
type: 'hostname',
redirectType: 'hostname',
};
const simpleParameters: SimpleRedirect['parameters'] = {
matcherType: 'hostname',
target: 'https://example.org/simple',
toMatch: 'example.com',
type: 'simple',
redirectType: 'simple',
};
test('parseRedirect', (t) => {
@ -101,6 +101,6 @@ test('Redirect.isMatch', (t) => {
test('Narrow match & redirect types', (t) => {
t.false(narrowMatchType('invalid'));
t.false(narrowRedirectType('invalid'));
t.true(matcherTypes.every((type) => narrowMatchType(type)));
t.true(redirectTypes.every((type) => narrowRedirectType(type)));
t.true(matcherTypes.every((value) => narrowMatchType(value)));
t.true(redirectTypes.every((value) => narrowRedirectType(value)));
});

View File

@ -12,8 +12,8 @@ Generated by [AVA](https://avajs.dev).
parameters: {
hostname: 'example.org',
matcherType: 'hostname',
redirectType: 'hostname',
toMatch: 'example.com',
type: 'hostname',
},
}
@ -22,9 +22,9 @@ Generated by [AVA](https://avajs.dev).
SimpleRedirect {
parameters: {
matcherType: 'hostname',
redirectType: 'simple',
target: 'https://example.org/simple',
toMatch: 'example.com',
type: 'simple',
},
}