Skip to content

Commit 76ee41e

Browse files
committed
feat: support --noCheck for transpiling without type-checking
1 parent 7cdd9a5 commit 76ee41e

File tree

14 files changed

+202
-38
lines changed

14 files changed

+202
-38
lines changed

docs/rules.md

Lines changed: 10 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/async_typecheck/BUILD.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
2+
3+
ts_config(
4+
name = "tsconfig",
5+
src = "tsconfig.json",
6+
visibility = [":__subpackages__"],
7+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
load("@aspect_bazel_lib//lib:testing.bzl", "assert_outputs")
2+
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
3+
4+
ts_project(
5+
name = "backend",
6+
async_typecheck = True,
7+
declaration = True,
8+
tsconfig = "//examples/async_typecheck:tsconfig",
9+
deps = ["//examples/async_typecheck/core"],
10+
)
11+
12+
assert_outputs(
13+
name = "test_backend_default_outputs",
14+
actual = "backend",
15+
expected = ["examples/async_typecheck/backend/index.js"],
16+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { IntersectionType } from '../core'
2+
3+
// Example object of IntersectionType
4+
const myObject: IntersectionType = {
5+
a: 42,
6+
b: 'backend',
7+
c: true,
8+
}
9+
10+
console.log(myObject)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
2+
3+
ts_project(
4+
name = "core",
5+
async_typecheck = True,
6+
declaration = True,
7+
tsconfig = "//examples/async_typecheck:tsconfig",
8+
visibility = ["//examples/async_typecheck:__subpackages__"],
9+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* A file with some non-trivial types, so type-checking it may take some time.
3+
* This helps to motivate the example: we'd like to be able to type-check the frontend and backend in parallel with this file.
4+
*/
5+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
6+
k: infer I
7+
) => void
8+
? I
9+
: never
10+
11+
// Example usage
12+
type UnionType = { a: number } | { b: string } | { c: boolean }
13+
14+
export type IntersectionType = UnionToIntersection<UnionType>
15+
16+
export const MyIntersectingValue: IntersectionType = {
17+
a: 1,
18+
b: '2',
19+
c: true,
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
2+
3+
ts_project(
4+
name = "frontend",
5+
async_typecheck = True,
6+
tsconfig = {
7+
"compilerOptions": {
8+
"declaration": True,
9+
"isolatedDeclarations": True,
10+
},
11+
},
12+
deps = ["//examples/async_typecheck/core"],
13+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { IntersectionType } from '../core'
2+
import { MyIntersectingValue } from '../core'
3+
4+
// Example object of IntersectionType
5+
const myObject: IntersectionType = {
6+
a: 42,
7+
b: 'frontend',
8+
c: true,
9+
}
10+
11+
const otherObject = MyIntersectingValue
12+
13+
console.log(myObject, otherObject, myObject === otherObject)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"isolatedDeclarations": true,
4+
"declaration": true
5+
},
6+
// Workaround https://github.com/microsoft/TypeScript/issues/59036
7+
"exclude": []
8+
}

ts/defs.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def ts_project(
4040
assets = [],
4141
extends = None,
4242
allow_js = False,
43+
async_typecheck = False,
4344
declaration = False,
4445
source_map = False,
4546
declaration_map = False,
@@ -153,6 +154,10 @@ def ts_project(
153154
See https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options
154155
Typically useful arguments for debugging are `--listFiles` and `--listEmittedFiles`.
155156
157+
async_typecheck: Whether to type-check asynchronously as a separate bazel action.
158+
Requires https://devblogs.microsoft.com/typescript/announcing-typescript-5-6/#the---nocheck-option6
159+
Requires https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations
160+
156161
transpiler: A custom transpiler tool to run that produces the JavaScript outputs instead of `tsc`.
157162
158163
Under `--@aspect_rules_ts//ts:default_to_tsc_transpiler`, the default is to use `tsc` to produce
@@ -416,6 +421,7 @@ def ts_project(
416421
incremental = incremental,
417422
preserve_jsx = preserve_jsx,
418423
composite = composite,
424+
async_typecheck = async_typecheck,
419425
declaration = declaration,
420426
declaration_dir = declaration_dir,
421427
source_map = source_map,

ts/private/ts_lib.bzl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ https://docs.aspect.build/rulesets/aspect_rules_js/docs/js_library#deps for more
8787
mandatory = True,
8888
allow_single_file = [".json"],
8989
),
90+
"async_typecheck": attr.bool(
91+
doc = """\
92+
Whether type-checking should be a separate action.
93+
94+
This allows the transpilation action to run without waiting for typings from dependencies.
95+
96+
Requires the typescript 5.6 [noCheck](https://www.typescriptlang.org/tsconfig#noCheck).
97+
98+
Requires tsconfig [isolatedDeclarations](https://www.typescriptlang.org/tsconfig#isolatedDeclarations)
99+
to allow declarations to be emitted without dependencies.
100+
""",
101+
),
90102
"validate": attr.bool(
91103
doc = """whether to add a Validation Action to verify the other attributes match
92104
settings in the tsconfig.json file""",

0 commit comments

Comments
 (0)