diff --git a/types/ts-nameof/index.d.ts b/types/ts-nameof/index.d.ts index 67a7fa25e6..a7850d695f 100644 --- a/types/ts-nameof/index.d.ts +++ b/types/ts-nameof/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for ts-nameof 2.0 +// Type definitions for ts-nameof 3.2 // Project: https://github.com/dsherret/ts-nameof#readme // Definitions by: David Sherret // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -12,4 +12,7 @@ declare namespace nameof { // tslint:disable-next-line no-unnecessary-generics function full(func: (obj: T) => void, periodIndex?: number): string; function full(obj: any, periodIndex?: number): string; + // tslint:disable-next-line no-unnecessary-generics + function toArray(func: (obj: T) => any[]): string[]; + function toArray(...args: any[]): string[]; } diff --git a/types/ts-nameof/ts-nameof-tests.ts b/types/ts-nameof/ts-nameof-tests.ts index 8c5a476253..21a53ec0f5 100644 --- a/types/ts-nameof/ts-nameof-tests.ts +++ b/types/ts-nameof/ts-nameof-tests.ts @@ -6,39 +6,49 @@ namespace TestNamespace { } class TestClass { - prop: string; + prop1 = ""; + prop2 = ""; } // nameof tests nameof(TestClass); // $ExpectType string nameof(); // $ExpectType string -nameof(t => t.prop); // $ExpectType string +nameof(t => t.prop1); // $ExpectType string // nameof.full tests const testInstance = new TestClass(); -nameof.full(testInstance.prop); // $ExpectType string -nameof.full(testInstance.prop, 1); // $ExpectType string +nameof.full(testInstance.prop1); // $ExpectType string +nameof.full(testInstance.prop1, 1); // $ExpectType string nameof.full(); // $ExpectType string nameof.full(1); // $ExpectType string -nameof.full(t => t.prop); // $ExpectType string -nameof.full(t => t.prop, 1); // $ExpectType string +nameof.full(t => t.prop1); // $ExpectType string +nameof.full(t => t.prop1, 1); // $ExpectType string + +// nameof.toArray tests +nameof.toArray(testInstance.prop1); // $ExpectType string[] +nameof.toArray(testInstance.prop1, testInstance.prop2); // $ExpectType string[] +nameof.toArray(t => [t.prop1]); // $ExpectType string[] // reference type test const myObj = { test: "" }; nameof(myObj); // $ExpectType string nameof.full(myObj); // $ExpectType string +nameof.toArray(myObj); // $ExpectType string[] // primitive type test const myStr = ""; nameof(myStr); // $ExpectType string nameof.full(myStr); // $ExpectType string +nameof.toArray(myStr); // $ExpectType string[] // null test const nullTypedVar = null; nameof(nullTypedVar); // $ExpectType string nameof.full(nullTypedVar); // $ExpectType string +nameof.toArray(nullTypedVar); // $ExpectType string[] // undefined test const undefinedTypedVar = undefined; nameof(undefinedTypedVar); // $ExpectType string nameof.full(undefinedTypedVar); // $ExpectType string +nameof.toArray(undefinedTypedVar); // $ExpectType string[]