Skip to content

Commit d4f6aff

Browse files
authored
fix(typings): set correct typing for tsconfig/tsConfig option (#2377)
Closes #2368
1 parent 9034677 commit d4f6aff

10 files changed

+16371
-65
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
dist
2+
src/tsconfig-raw-types.d.ts
23

34
# Logs
45
logs

package-lock.json

+16,188-57
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"description": "A preprocessor with source maps support to help use TypeScript with Jest",
1010
"scripts": {
11-
"prebuild": "node scripts/clean-dist.js",
11+
"prebuild": "node scripts/pre-build.js",
1212
"build": "tsc -p tsconfig.build.json",
1313
"postbuild": "node scripts/post-build.js",
1414
"clean": "node scripts/clean.js",
@@ -32,7 +32,8 @@
3232
"prepublishOnly": "npm run test",
3333
"preversion": "npm run test",
3434
"update:e2e": "node scripts/update-e2e-templates.js",
35-
"version": "npm run changelog && git add CHANGELOG.md"
35+
"version": "npm run changelog && git add CHANGELOG.md",
36+
"raw-tsconfig-types": "node scripts/tsconfig-raw-types.js"
3637
},
3738
"repository": {
3839
"type": "git",
@@ -114,7 +115,9 @@
114115
"husky": "4.x",
115116
"jest": "26.x",
116117
"js-yaml": "latest",
118+
"json-schema-to-typescript": "^10.1.3",
117119
"lint-staged": "latest",
120+
"node-fetch": "^2.6.1",
118121
"npm-run-all": "latest",
119122
"prettier": "2.x",
120123
"source-map": "latest",
File renamed without changes.

scripts/tsconfig-raw-types.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { compile } = require('json-schema-to-typescript')
2+
const fs = require('fs')
3+
const fetch = require('node-fetch')
4+
const path = require('path')
5+
6+
void (async () => {
7+
const response = await fetch('https://json.schemastore.org/tsconfig')
8+
const tsconfigSchema = await response.json()
9+
const rawTsconfig = await compile(tsconfigSchema)
10+
fs.writeFileSync(path.join(process.cwd(), 'src', 'tsconfig-raw-types.d.ts'), rawTsconfig)
11+
})()

src/config/config-set.spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ describe('parsedTsConfig', () => {
8484
})
8585
expect(cs.parsedTsConfig.options).toMatchObject({
8686
module: ts.ModuleKind.CommonJS,
87-
rootDir: normalizeSlashes(resolve(__dirname, '..')),
8887
skipLibCheck: true,
8988
})
9089
})

src/config/config-set.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { Deprecations, Errors, ImportReasons, interpolate } from '../utils/messa
4545
import { normalizeSlashes } from '../utils/normalize-slashes'
4646
import { sha1 } from '../utils/sha1'
4747
import { TSError } from '../utils/ts-error'
48+
import type { RawCompilerOptions } from '../tsconfig-raw'
4849

4950
/**
5051
* @internal
@@ -421,9 +422,9 @@ export class ConfigSet {
421422
* Load TypeScript configuration. Returns the parsed TypeScript config and
422423
* any `tsConfig` options specified in ts-jest tsConfig
423424
*/
424-
protected _resolveTsConfig(compilerOptions?: CompilerOptions, resolvedConfigFile?: string): Record<string, any>
425+
protected _resolveTsConfig(compilerOptions?: RawCompilerOptions, resolvedConfigFile?: string): Record<string, any>
425426
// eslint-disable-next-line no-dupe-class-members
426-
protected _resolveTsConfig(compilerOptions?: CompilerOptions, resolvedConfigFile?: string): ParsedCommandLine {
427+
protected _resolveTsConfig(compilerOptions?: RawCompilerOptions, resolvedConfigFile?: string): ParsedCommandLine {
427428
let config = { compilerOptions: Object.create(null) }
428429
let basePath = normalizeSlashes(this.rootDir)
429430
const ts = this.compilerModule

src/tsconfig-raw.ts

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
export interface RawCompilerOptions {
2+
charset?: string
3+
composite?: boolean
4+
declaration?: boolean
5+
declarationDir?: string | null
6+
diagnostics?: boolean
7+
disableReferencedProjectLoad?: boolean
8+
emitBOM?: boolean
9+
emitDeclarationOnly?: boolean
10+
incremental?: boolean
11+
tsBuildInfoFile?: string
12+
inlineSourceMap?: boolean
13+
inlineSources?: boolean
14+
jsx?: 'preserve' | 'react' | 'react-jsx' | 'react-jsxdev' | 'react-native'
15+
reactNamespace?: string
16+
jsxFactory?: string
17+
jsxFragmentFactory?: string
18+
jsxImportSource?: string
19+
listFiles?: boolean
20+
mapRoot?: string
21+
module?: 'CommonJS' | 'AMD' | 'System' | 'UMD' | 'ES6' | 'ES2015' | 'ES2020' | 'ESNext' | 'None' | string
22+
moduleResolution?: 'Classic' | 'Node'
23+
newLine?: 'crlf' | 'lf'
24+
noEmit?: boolean
25+
noEmitHelpers?: boolean
26+
noEmitOnError?: boolean
27+
noImplicitAny?: boolean
28+
noImplicitThis?: boolean
29+
noUnusedLocals?: boolean
30+
noUnusedParameters?: boolean
31+
noLib?: boolean
32+
noResolve?: boolean
33+
noStrictGenericChecks?: boolean
34+
skipDefaultLibCheck?: boolean
35+
skipLibCheck?: boolean
36+
outFile?: string
37+
outDir?: string
38+
preserveConstEnums?: boolean
39+
preserveSymlinks?: boolean
40+
preserveWatchOutput?: boolean
41+
pretty?: boolean
42+
removeComments?: boolean
43+
rootDir?: string
44+
isolatedModules?: boolean
45+
sourceMap?: boolean
46+
sourceRoot?: string
47+
suppressExcessPropertyErrors?: boolean
48+
suppressImplicitAnyIndexErrors?: boolean
49+
target?: 'ES3' | 'ES5' | 'ES6' | 'ES2015' | 'ES2016' | 'ES2017' | 'ES2018' | 'ES2019' | 'ES2020' | 'ESNext' | string
50+
watch?: boolean
51+
fallbackPolling?: 'fixedPollingInterval' | 'priorityPollingInterval' | 'dynamicPriorityPolling'
52+
watchDirectory?: 'useFsEvents' | 'fixedPollingInterval' | 'dynamicPriorityPolling'
53+
watchFile?:
54+
| 'fixedPollingInterval'
55+
| 'priorityPollingInterval'
56+
| 'dynamicPriorityPolling'
57+
| 'useFsEvents'
58+
| 'useFsEventsOnParentDirectory'
59+
experimentalDecorators?: boolean
60+
emitDecoratorMetadata?: boolean
61+
allowUnusedLabels?: boolean
62+
noImplicitReturns?: boolean
63+
noUncheckedIndexedAccess?: boolean
64+
noFallthroughCasesInSwitch?: boolean
65+
allowUnreachableCode?: boolean
66+
forceConsistentCasingInFileNames?: boolean
67+
generateCpuProfile?: string
68+
baseUrl?: string
69+
paths?: {
70+
[k: string]: string[]
71+
}
72+
plugins?: {
73+
name?: string
74+
[k: string]: unknown
75+
}[]
76+
rootDirs?: string[]
77+
typeRoots?: string[]
78+
types?: string[]
79+
traceResolution?: boolean
80+
allowJs?: boolean
81+
noErrorTruncation?: boolean
82+
allowSyntheticDefaultImports?: boolean
83+
noImplicitUseStrict?: boolean
84+
listEmittedFiles?: boolean
85+
disableSizeLimit?: boolean
86+
lib?: (
87+
| 'ES5'
88+
| 'ES6'
89+
| 'ES2015'
90+
| 'ES2015.Collection'
91+
| 'ES2015.Core'
92+
| 'ES2015.Generator'
93+
| 'ES2015.Iterable'
94+
| 'ES2015.Promise'
95+
| 'ES2015.Proxy'
96+
| 'ES2015.Reflect'
97+
| 'ES2015.Symbol.WellKnown'
98+
| 'ES2015.Symbol'
99+
| 'ES2016'
100+
| 'ES2016.Array.Include'
101+
| 'ES2017'
102+
| 'ES2017.Intl'
103+
| 'ES2017.Object'
104+
| 'ES2017.SharedMemory'
105+
| 'ES2017.String'
106+
| 'ES2017.TypedArrays'
107+
| 'ES2018'
108+
| 'ES2018.AsyncGenerator'
109+
| 'ES2018.AsyncIterable'
110+
| 'ES2018.Intl'
111+
| 'ES2018.Promise'
112+
| 'ES2018.Regexp'
113+
| 'ES2019'
114+
| 'ES2019.Array'
115+
| 'ES2019.Object'
116+
| 'ES2019.String'
117+
| 'ES2019.Symbol'
118+
| 'ES2020'
119+
| 'ES2020.BigInt'
120+
| 'ES2020.Promise'
121+
| 'ES2020.String'
122+
| 'ES2020.Symbol.WellKnown'
123+
| 'ESNext'
124+
| 'ESNext.Array'
125+
| 'ESNext.AsyncIterable'
126+
| 'ESNext.BigInt'
127+
| 'ESNext.Intl'
128+
| 'ESNext.Promise'
129+
| 'ESNext.String'
130+
| 'ESNext.Symbol'
131+
| 'DOM'
132+
| 'DOM.Iterable'
133+
| 'ScriptHost'
134+
| 'WebWorker'
135+
| 'WebWorker.ImportScripts'
136+
)[]
137+
strictNullChecks?: boolean
138+
maxNodeModuleJsDepth?: number
139+
importHelpers?: boolean
140+
importsNotUsedAsValues?: 'remove' | 'preserve' | 'error'
141+
alwaysStrict?: boolean
142+
strict?: boolean
143+
strictBindCallApply?: boolean
144+
downlevelIteration?: boolean
145+
checkJs?: boolean
146+
strictFunctionTypes?: boolean
147+
strictPropertyInitialization?: boolean
148+
esModuleInterop?: boolean
149+
allowUmdGlobalAccess?: boolean
150+
keyofStringsOnly?: boolean
151+
useDefineForClassFields?: boolean
152+
declarationMap?: boolean
153+
resolveJsonModule?: boolean
154+
assumeChangesOnlyAffectDirectDependencies?: boolean
155+
extendedDiagnostics?: boolean
156+
listFilesOnly?: boolean
157+
disableSourceOfProjectReferenceRedirect?: boolean
158+
disableSolutionSearching?: boolean
159+
[k: string]: unknown
160+
}

src/types.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type * as _babel from 'babel__core'
44
import type * as _ts from 'typescript'
55

66
import type { ConfigSet } from './config/config-set'
7+
import type { RawCompilerOptions } from './tsconfig-raw'
78

89
/**
910
* @internal
@@ -47,7 +48,7 @@ export interface TsJestGlobalOptions {
4748
* @default undefined uses the default tsconfig file
4849
* @alias tsconfig
4950
*/
50-
tsConfig?: boolean | string | _ts.CompilerOptions
51+
tsConfig?: boolean | string | RawCompilerOptions
5152

5253
/**
5354
* Compiler options. It can be:
@@ -59,7 +60,7 @@ export interface TsJestGlobalOptions {
5960
* @default undefined uses the default tsconfig file
6061
* @alias tsConfig
6162
*/
62-
tsconfig?: boolean | string | _ts.CompilerOptions
63+
tsconfig?: boolean | string | RawCompilerOptions
6364

6465
/**
6566
* packageJson. It can be:

tsconfig.build.json

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"removeComments": true,
1010
"stripInternal": true,
1111
"outDir": "dist",
12-
"rootDir": "src"
1312
},
1413
"include": ["src"],
1514
"exclude": [

0 commit comments

Comments
 (0)