Skip to content

Commit 3d7eb13

Browse files
committed
feat(builtin): add a DeclarationInfo provider
This gives us a principled way for rules to generate and consume TypeScript typings
1 parent 0229ae5 commit 3d7eb13

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

declaration_provider.bzl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""This module contains a provider for TypeScript typings files (.d.ts)"""
2+
3+
def provide_declarations(**kwargs):
4+
"""Factory function for creating checked declarations with externs.
5+
6+
Do not directly construct DeclarationInfo()
7+
"""
8+
9+
# TODO: add some checking actions to ensure the declarations are well-formed
10+
return DeclarationInfo(**kwargs)
11+
12+
DeclarationInfo = provider(
13+
doc = """The DeclarationInfo provider allows JS rules to communicate typing information.
14+
TypeScript's .d.ts files are used as the interop format for describing types.
15+
16+
Do not create DeclarationInfo instances directly, instead use the provide_declarations factory function.
17+
18+
TODO(alexeagle): The ts_library#deps attribute should require that this provider is attached.
19+
20+
Note: historically this was a subset of the string-typed "typescript" provider.
21+
""",
22+
# TODO: if we ever enable --declarationMap we will have .d.ts.map files too
23+
fields = {
24+
"declarations": "A depset of .d.ts files produced by this rule",
25+
"transitive_declarations": """A depset of .d.ts files produced by this rule and all its transitive dependencies.
26+
This prevents needing an aspect in rules that consume the typings, which improves performance.""",
27+
},
28+
)

0 commit comments

Comments
 (0)