The library schematics example I downloaded on the official website of angular encountered the following error when running the command line NPM run build:
npm run build
my- [email protected] build c:\Code\SPA\schematics-for-libraries\projects\my-lib
tsc -p tsconfig.schematics.json
schematics/my-service/index.ts:39:7 – error TS2322: Type ‘string | number | boolean | JsonArray | JsonObject | null | undefined’ is not assignable to type ‘string | undefined’.
Type ‘null’ is not assignable to type ‘string | undefined’.
39 options.project = workspace.extensions.defaultProject;
schematics/my-service/index.ts:42:44 – error TS2345: Argument of type ‘string | undefined’ is not assignable to parameter of type ‘string’.
Type ‘undefined’ is not assignable to type ‘string’.
The data type of this project is defined in schema.ts, so it can be adjusted to be consistent with workspace.extensions.defaultproject.
After modification, a new problem is encountered: cannot find name ‘jsonarray’
In fact, you can add as string directly to the original code position, which means to tell the compiler that the programmer knows very well that in this context, the type of workspace.extensions.defaultproject,
Another error was encountered after repair:
‘options’ is declared but its value is never read.ts(6133)
The solution to this error is relatively simple:
The parameter name can be preceded by an underscore.
Finally, NPM run build is successfully executed:
More Jerry’s original articles can be found in: “Wang Zixi”:
- Wechat applet error report summary [How to Solve]
- [Solved] Element-ui Error: [Vue warn]: Invalid prop: type check failed for prop “index”. Expected String with value “1”, got Number with value 1
- How to Solve ReferenceError: internalBinding is not defined
- How to Solve Java Error: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList
- python3 can’t concat str to bytes
- [Solved] Possible reasons why NPM run build cannot package NPM err! missing script: build
- [Solved] Android.content.res.Resources$NotFoundException: String resource ID #0x0
- Git Conflict Error: commit your changes or stash them before you can merge. [How to Solve]
- [Solved] Mybatis Mapping Error: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘id’ in ‘class java.lang.String