已在tsconfig.json排除的survey.d.ts仍触发tsc警告,求原因
survey.d.ts Let’s walk through the common reasons your fixes aren’t working, and how to resolve them:
1. TSConfig exclude Doesn’t Control TSLint
The exclude array in tsconfig.json tells the TypeScript compiler to ignore the file, but TSLint uses its own independent configuration to decide which files to scan. TSLint won’t automatically respect tsconfig’s exclude rules unless you explicitly set it up to do so.
2. /* tslint:disable */ Might Not Be Properly Placed
For the file-wide disable comment to take effect, it needs to be the very first line of the file—no blank lines, no other comments, no leading whitespace allowed. Double-check that your survey.d.ts starts exactly with:
/* tslint:disable */ // Rest of your file content
3. Wildcard Pattern Edge Cases
While src/app/**/*.d.ts should recursively match all .d.ts files under src/app, there could be small issues breaking the pattern:
- Case sensitivity: If you’re on a case-sensitive OS (like Linux), make sure the rule’s path matches the actual file path exactly (e.g.,
Survey.d.tsvssurvey.d.ts). - Relative path context: If your
tsconfig.jsonisn’t in the project root, the exclude path might resolve incorrectly. Test with a more specific pattern likesrc/app/dynamic-pages/survey.d.tsto rule out wildcard ambiguity.
4. TSLint Configuration Overrides
Check your tslint.json for settings that might be overriding your disable:
- Add an
excludearray directly totslint.jsonto tell TSLint to skip these files entirely:{ "exclude": ["src/app/**/*.d.ts"], // Other TSLint settings } - If you’re extending a TSLint preset, some presets enforce rules for
.d.tsfiles that bypass file-wide disable comments. Check the preset’s documentation for any declaration-file-specific rules.
Quick Fixes to Test
- Restart your editor/IDE: Cached lint results often stick around even after configuration changes.
- Clear TypeScript’s cache: Run
tsc --clearCachein your terminal to wipe old compilation data. - Target the specific rule: If you know which rule is throwing the warning, disable it directly for the file in
tslint.json:{ "rules": { "no-unused-variable": { "severity": "off", "exclude": ["src/app/dynamic-pages/survey.d.ts"] } } }
内容的提问来源于stack exchange,提问作者OctaviaLo

