You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tests/cases/conformance/types/literal/templateLiteralTypesPatterns.ts(7,7): error TS2322: Type '"no slash"' is not assignable to type '`/${string}`'.
2
+
tests/cases/conformance/types/literal/templateLiteralTypesPatterns.ts(14,10): error TS2345: Argument of type '"example.com/noprotocol"' is not assignable to parameter of type '`http://${string}` | `https://${string}` | `ftp://${string}`'.
3
+
tests/cases/conformance/types/literal/templateLiteralTypesPatterns.ts(16,10): error TS2345: Argument of type '"gopher://example.com/protocol"' is not assignable to parameter of type '`http://${string}` | `https://${string}` | `ftp://${string}`'.
!!! error TS2322: Type '"no slash"' is not assignable to type '`/${string}`'.
16
+
17
+
type Protocol<T extends string, U extends string> = `${T}://${U}`;
18
+
function download(hostSpec: Protocol<"http" | "https" | "ftp", string>) { }
19
+
// ok, has protocol
20
+
download("http://example.com/protocol");
21
+
// issues error - no protocol
22
+
download("example.com/noprotocol");
23
+
~~~~~~~~~~~~~~~~~~~~~~~~
24
+
!!! error TS2345: Argument of type '"example.com/noprotocol"' is not assignable to parameter of type '`http://${string}` | `https://${string}` | `ftp://${string}`'.
25
+
// issues error, incorrect protocol
26
+
download("gopher://example.com/protocol");
27
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28
+
!!! error TS2345: Argument of type '"gopher://example.com/protocol"' is not assignable to parameter of type '`http://${string}` | `https://${string}` | `ftp://${string}`'.
0 commit comments