@@ -42,9 +42,10 @@ export function createProjectService(
42
42
jsDocParsingMode : ts . JSDocParsingMode | undefined ,
43
43
tsconfigRootDir : string | undefined ,
44
44
) : ProjectServiceSettings {
45
+ const optionsRawObject = typeof optionsRaw === 'object' ? optionsRaw : { } ;
45
46
const options = {
46
47
defaultProject : 'tsconfig.json' ,
47
- ...( typeof optionsRaw === 'object' && optionsRaw ) ,
48
+ ...optionsRawObject ,
48
49
} ;
49
50
validateDefaultProjectForFilesGlob ( options . allowDefaultProject ) ;
50
51
@@ -126,7 +127,7 @@ export function createProjectService(
126
127
} ) ;
127
128
128
129
log ( 'Enabling default project: %s' , options . defaultProject ) ;
129
- let configFile : ts . ParsedCommandLine ;
130
+ let configFile : ts . ParsedCommandLine | undefined ;
130
131
131
132
try {
132
133
configFile = getParsedConfigFile (
@@ -135,18 +136,22 @@ export function createProjectService(
135
136
tsconfigRootDir ,
136
137
) ;
137
138
} catch ( error ) {
138
- throw new Error (
139
- `Could not read project service default project '${ options . defaultProject } ': ${ ( error as Error ) . message } ` ,
140
- ) ;
139
+ if ( optionsRawObject . defaultProject ) {
140
+ throw new Error (
141
+ `Could not read project service default project '${ options . defaultProject } ': ${ ( error as Error ) . message } ` ,
142
+ ) ;
143
+ }
141
144
}
142
145
143
- service . setCompilerOptionsForInferredProjects (
144
- // NOTE: The inferred projects API is not intended for source files when a tsconfig
145
- // exists. There is no API that generates an InferredProjectCompilerOptions suggesting
146
- // it is meant for hard coded options passed in. Hard asserting as a work around.
147
- // See https://github.com/microsoft/TypeScript/blob/27bcd4cb5a98bce46c9cdd749752703ead021a4b/src/server/protocol.ts#L1904
148
- configFile . options as ts . server . protocol . InferredProjectCompilerOptions ,
149
- ) ;
146
+ if ( configFile ) {
147
+ service . setCompilerOptionsForInferredProjects (
148
+ // NOTE: The inferred projects API is not intended for source files when a tsconfig
149
+ // exists. There is no API that generates an InferredProjectCompilerOptions suggesting
150
+ // it is meant for hard coded options passed in. Hard asserting as a work around.
151
+ // See https://github.com/microsoft/TypeScript/blob/27bcd4cb5a98bce46c9cdd749752703ead021a4b/src/server/protocol.ts#L1904
152
+ configFile . options as ts . server . protocol . InferredProjectCompilerOptions ,
153
+ ) ;
154
+ }
150
155
151
156
return {
152
157
allowDefaultProject : options . allowDefaultProject ,
0 commit comments