1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
/// <reference path="fourslash.ts" />
// @strict: true
// @filename: /bar.ts
////export type Bar = Record<string, string>
////export function bar<T extends Bar>(obj: { prop: T }) {}
// @filename: /foo.ts
////import { bar } from "./bar";
////
////export function f1<T>(x: T) {
//// bar({ prop: x })
////}
////
////function f2<T>(x: T) {
//// const y: `${number}` = x;
////}
////
////interface Fn<T extends string> {}
////function f3<T>(x: Fn<T>) {
////}
////
////function f4<T = `${number}`>(x: T) {
//// const y: `${number}` = x;
////}
////
////interface TypeRef<T extends {}> {
//// x: T
////}
////function f5<T>(): TypeRef</**/T> {
//// throw undefined as any as TypeRef<T>;
////}
goTo.file("/foo.ts");
verify.codeFixAll({
fixId: "addMissingConstraint",
fixAllDescription: ts.Diagnostics.Add_extends_constraint_to_all_type_parameters.message,
newFileContent:
"import { bar } from \"./bar\";\n\n" +
"export function f1<T extends Bar>(x: T) {\n" +
" bar({ prop: x })\n" +
"}\n\n" +
"function f2<T extends \`${number}\`>(x: T) {\n" +
" const y: `${number}` = x;\n" +
"}\n\n" +
"interface Fn<T extends string> {}\n" +
"function f3<T extends string>(x: Fn<T>) {\n" +
"}\n\n" +
"function f4<T extends `${number}` = `${number}`>(x: T) {\n" +
" const y: `${number}` = x;\n" +
"}\n\n" +
"interface TypeRef<T extends {}> {\n" +
" x: T\n" +
"}\n" +
"function f5<T extends {}>(): TypeRef<T> {\n" +
" throw undefined as any as TypeRef<T>;\n" +
"}"
});
|