@@ -40,6 +40,7 @@ def ts_project(
40
40
assets = [],
41
41
extends = None ,
42
42
allow_js = False ,
43
+ isolated_declarations = None ,
43
44
declaration = False ,
44
45
source_map = False ,
45
46
declaration_map = False ,
@@ -152,6 +153,10 @@ def ts_project(
152
153
See https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options
153
154
Typically useful arguments for debugging are `--listFiles` and `--listEmittedFiles`.
154
155
156
+ isolated_declarations: Whether to enforce that declaration output (.d.ts file) can be produced for a
157
+ single source file at a time. Requires some additional explicit types on exported symbols.
158
+ See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations
159
+
155
160
transpiler: A custom transpiler tool to run that produces the JavaScript outputs instead of `tsc`.
156
161
157
162
Under `--@aspect_rules_ts//ts:default_to_tsc_transpiler`, the default is to use `tsc` to produce
@@ -280,6 +285,8 @@ def ts_project(
280
285
allow_js = compiler_options .setdefault ("allowJs" , allow_js )
281
286
if resolve_json_module != None :
282
287
resolve_json_module = compiler_options .setdefault ("resolveJsonModule" , resolve_json_module )
288
+ if isolated_declarations != None :
289
+ isolated_declarations = compiler_options .setdefault ("isolatedDeclarations" , isolated_declarations )
283
290
284
291
# These options are always passed on the tsc command line so don't include them
285
292
# in the tsconfig. At best they're redundant, but at worst we'll have a conflict
@@ -321,8 +328,9 @@ def ts_project(
321
328
else :
322
329
# To stitch together a tree of ts_project where transpiler is a separate rule,
323
330
# we have to produce a few targets
324
- tsc_target_name = "%s_typings " % name
331
+ tsc_target_name = "%s_tsc " % name
325
332
transpile_target_name = "%s_transpile" % name
333
+ typings_target_name = "%s_typings" % name
326
334
typecheck_target_name = "%s_typecheck" % name
327
335
test_target_name = "%s_typecheck_test" % name
328
336
@@ -342,14 +350,31 @@ def ts_project(
342
350
else :
343
351
fail ("transpiler attribute should be a rule/macro or a skylib partial. Got " + type (transpiler ))
344
352
345
- # Users should build this target to get a failed build when typechecking fails
346
- native .filegroup (
347
- name = typecheck_target_name ,
348
- srcs = [tsc_target_name ],
349
- # This causes the types to be produced, which in turn triggers the tsc action to typecheck
350
- output_group = "types" ,
351
- ** common_kwargs
352
- )
353
+ if isolated_declarations :
354
+ # Users should build this target to get a failed build when typechecking fails
355
+ native .filegroup (
356
+ name = typecheck_target_name ,
357
+ srcs = [tsc_target_name ],
358
+ output_group = "typecheck" ,
359
+ ** common_kwargs
360
+ )
361
+
362
+ native .filegroup (
363
+ name = typings_target_name ,
364
+ srcs = [tsc_target_name ],
365
+ # This causes the types to be produced, which in turn triggers the tsc action to typecheck
366
+ output_group = "types" ,
367
+ ** common_kwargs
368
+ )
369
+ else :
370
+ # Users should build this target to get a failed build when typechecking fails
371
+ native .filegroup (
372
+ name = typecheck_target_name ,
373
+ srcs = [tsc_target_name ],
374
+ # This causes the types to be produced, which in turn triggers the tsc action to typecheck
375
+ output_group = "types" ,
376
+ ** common_kwargs
377
+ )
353
378
354
379
# Ensures the typecheck target gets built under `bazel test --build_tests_only`
355
380
build_test (
@@ -389,6 +414,7 @@ def ts_project(
389
414
incremental = incremental ,
390
415
preserve_jsx = preserve_jsx ,
391
416
composite = composite ,
417
+ isolated_declarations = isolated_declarations ,
392
418
declaration = declaration ,
393
419
declaration_dir = declaration_dir ,
394
420
source_map = source_map ,
0 commit comments