TypeScript Version: 3.7.1-rc
Search Terms:
VS2019, for-in, es5, downlevelIteration, TS2354, tslib
Environment
Code
/**
* Count the same characters from the left site of a given text
* @param text The text that should contain the characters
* @param characterToCount The character to count
*/
export function CountFromLeft(text: string, characterToCount: string): number
{
let count = 0;
for(let character of text)
{
if(character === characterToCount)
{
count++;
continue;
}
else
{
break;
}
}
return count;
}
tsconfig.json
{
"compilerOptions":
{
"allowJs": false,
"allowSyntheticDefaultImports": false,
"allowUmdGlobalAccess": false,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"alwaysStrict": true,
// "baseUrl": "",
// "charset": "",
"checkJs": false,
"composite": false,
"declaration": false,
// "declarationDir": "",
"declarationMap": false,
"disableSizeLimit": false,
"diagnostics": false,
"downlevelIteration": true,
"emitBOM": true,
"emitDeclarationOnly": false,
"emitDecoratorMetadata": true,
"esModuleInterop": false,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"incremental": false,
"inlineSourceMap": true,
"inlineSources": true,
"isolatedModules": false,
"jsx": "preserve",
// "jsxFactory": "React.createElement",
"keyofStringsOnly": false,
// "lib": [],
"listEmittedFiles": false,
"listFiles": false,
// "mapRoot": "",
// "maxNodeModuleJsDepth": 0,
"module": "amd",
"moduleResolution": "node",
"newLine": "CRLF",
"noEmit": false,
"noEmitHelpers": false,
"noEmitOnError": true,
"noErrorTruncation": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitUseStrict": false,
"noLib": false,
"noResolve": false,
"noStrictGenericChecks": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
// "outDir": "",
// "outFile": "",
// "paths": {},
// "plugins": [],
"preserveConstEnums": false,
"preserveSymlinks": true,
"preserveWatchOutput": false,
"pretty": true,
// "reactNamespace": "",
"removeComments": true,
"resolveJsonModule": true,
// "rootDir": "",
// "rootDirs": [],
// "skipDefaultLibCheck": false,
"skipLibCheck": false,
"sourceMap": false,
"strict": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"stripInternal": true,
// "sourceRoot": "",
"suppressExcessPropertyErrors": false,
"suppressImplicitAnyIndexErrors": false,
"target": "es5",
"traceResolution": false,
// "tsBuildInfoFile": "",
// "typeRoots": [],
// "types": [],
"watch": false
}
}
Expected behavior:
No error -> Build a ES5 compatible JavaScript function/file (working in IE 11)
Actual behavior:
Error: TS2354 (TS) This syntax requires an imported utility, but the "tslib" module was not found.
Related Issues:
possible: #17642
tsconfig contains "importHelpers": true, so you need to install tslib as a dependency of your project (e.g. npm i tslib or yarn add tslib) .
see: https://www.typescriptlang.org/docs/handbook/compiler-options.html
You can also set importHelpers to false (its default value), which would mean ES5 helpers will be inlined instead of being imported.
Thanks 👍
You can also set importHelpers to false (its default value), which would mean ES5 helpers will be inlined instead of being imported.
-> closed as not a bug -> missing documentation
in typescript version 3.9.3。 when I set importHelpers false。
The build result also import { __rest } from "tslib";
The tsconf.json like this:
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"allowJs": false,
"noEmitOnError": true,
"downlevelIteration": true,
"alwaysStrict": true,
"outDir": "dist",
"sourceMap": false,
"declaration": false,
"removeComments": false,
"esModuleInterop":true,
"strict": true,
"noImplicitReturns": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitAny": true,
"noImplicitThis": true,
"jsx": "react-native",
"resolveJsonModule": true,
"experimentalDecorators": true,
"lib": ["es6"],
"importHelpers": false,
"typeRoots": [
"./node_modules/@qnpm",
"./node_modules/@types"
],
"types": [
"node",
"react",
"react-native",
"qunar-react-native-types"
]
},
"include": ["packages/**/*.ts", "packages/**/*.tsx"]
}
sorry。 I debug, in custom compile code。 The dever set Config default to true。
Most helpful comment
tsconfig contains
"importHelpers": true, so you need to installtslibas a dependency of your project (e.g.npm i tsliboryarn add tslib) .see: https://www.typescriptlang.org/docs/handbook/compiler-options.html
You can also set
importHelperstofalse(its default value), which would mean ES5 helpers will be inlined instead of being imported.