Fix type errors in older versions of Angular

This commit is contained in:
Valentin Palkovic 2024-03-17 10:22:55 +01:00
parent 0c93db1272
commit 762a61f2df
2 changed files with 18 additions and 0 deletions

View File

@ -115,6 +115,7 @@
},
"builders": "dist/builders/builders.json",
"bundler": {
"post": "./scripts/postbuild.js",
"tsConfig": "tsconfig.build.json"
},
"gitHead": "e6a7fd8a655c69780bc20b9749c2699e44beae17"

View File

@ -0,0 +1,17 @@
/**
* This postbuild fix is needed to add a ts-ignore to the generated public-types.d.ts file.
* The AngularCore.InputSignal and AngularCore.InputSignalWithTransform types do not exist in Angular
* versions < 17.2. In these versions, the unresolved types will error and prevent Storybook from starting/building.
* This postbuild script adds a ts-ignore statement above the unresolved types to prevent the errors.
*/
const fs = require('fs');
const path = require('path');
const filePath = path.join(__dirname, '../dist/client/public-types.d.ts');
const fileContent = fs.readFileSync(filePath, 'utf8');
const newContent = fileContent.replaceAll(
/(\[K in keyof T\]: T\[K\] extends AngularCore.InputSignal)/g,
' // @ts-ignore\n $1'
);
fs.writeFileSync(filePath, newContent, 'utf8');