Disallow TypeScript-producing rules as srcs in ts_library and ng_module.

Previously, it was possible to write a TypeScript rule depending on
another TypeScript rule:

    ts_library(name = "a", srcs = ["a.ts"])
    ts_library(name = "b", srcs = [":a"])

Because the default "files" output of "a" above is "a.d.ts", "b" will
accept this input and treat it as a regular ".d.ts" source file.

That's very confusing, but also wrong on multiple levels: it'll treat
the symbols from the .d.ts file as external, preventing renaming and
generating externs. It also has a change to subtly break module
resolution, and generally confuse tsickle.

PiperOrigin-RevId: 221794400
diff --git a/internal/common/compilation.bzl b/internal/common/compilation.bzl
index e658420..06f3093 100644
--- a/internal/common/compilation.bzl
+++ b/internal/common/compilation.bzl
@@ -227,6 +227,16 @@
             # Sources can be in sub-folders, but not in sub-packages.
             fail("Sources must be in the same package as the ts_library rule, " +
                  "but %s is not in %s" % (src.label, ctx.label.package), "srcs")
+        if hasattr(src, "typescript"):
+            # Guard against users accidentally putting deps into srcs by
+            # rejecting all srcs values that have a TypeScript provider.
+            # TS rules produce a ".d.ts" file, which is a valid input in "srcs",
+            # and will then be compiled as a source .d.ts file would, creating
+            # externs etc.
+            fail(
+                "must not reference any TypeScript rules - did you mean deps?",
+                "srcs",
+            )
 
         for f in src.files:
             has_sources = True