From ce819e40f393be7509cd86d6b9962bb0a9fbacd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juho=20Veps=C3=A4l=C3=A4inen?= Date: Tue, 12 May 2020 11:04:00 +0300 Subject: [PATCH] fix: Make TypeScript typing more accurate for Options and generate js/css references --- src/index.ts | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index bf2be5a..cac4a26 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,7 +17,7 @@ type Options = { publicPath?: string; context?: Context; template?: ( - args: Context | { css: string; js: string; publicPath: string } + args: Context & Files & { publicPath: string } ) => string | Promise; chunks?: string[]; }; @@ -76,8 +76,12 @@ function generateCSSReferences({ }: { files: string[]; publicPath: string; - attributes: { rel?: string }; -}) { + attributes: (Attributes & { rel?: string }) | undefined; +}): string { + if (!attributes) { + return ''; + } + const allAttributes = { ...attributes, rel: 'rel' in attributes ? attributes.rel : 'stylesheet', @@ -95,11 +99,18 @@ function generateJSReferences({ files = [], publicPath = '', attributes = {}, -}) { - attributes = generateAttributes(attributes); - +}: { + files: string[]; + publicPath: string; + attributes: Attributes; +}): string { return files - .map((file) => ``) + .map( + (file) => + `` + ) .join(''); }