[ts-nameof] Add nameof.interpolate (#38706)

* ts-nameof: Add nameof.interpolate

* Fix old ts vs new ts difference with string literal types.
This commit is contained in:
David Sherret 2019-10-03 17:31:28 -04:00 committed by Ryan Cavanaugh
parent c3042f83c5
commit 56f0f57acf
2 changed files with 5 additions and 1 deletions

View File

@ -1,4 +1,4 @@
// Type definitions for ts-nameof 3.2
// Type definitions for ts-nameof 4.0
// Project: https://github.com/dsherret/ts-nameof#readme
// Definitions by: David Sherret <https://github.com/dsherret>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@ -15,4 +15,5 @@ declare namespace nameof {
// tslint:disable-next-line no-unnecessary-generics
function toArray<T>(func: (obj: T) => any[]): string[];
function toArray(...args: any[]): string[];
function interpolate<T>(value: T): T;
}

View File

@ -29,6 +29,9 @@ nameof.toArray(testInstance.prop1); // $ExpectType string[]
nameof.toArray(testInstance.prop1, testInstance.prop2); // $ExpectType string[]
nameof.toArray<TestClass>(t => [t.prop1]); // $ExpectType string[]
// nameof.interpolate tests
nameof.interpolate("" as string); // $ExpectType string
// reference type test
const myObj = { test: "" };
nameof(myObj); // $ExpectType string