mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-01 15:50:13 +00:00
Add ts-nameof 2.1. (#36608)
This commit is contained in:
committed by
Ryan Cavanaugh
parent
71f8b36c56
commit
97925867a8
5
types/ts-nameof/index.d.ts
vendored
5
types/ts-nameof/index.d.ts
vendored
@@ -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 <https://github.com/dsherret>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
@@ -12,4 +12,7 @@ declare namespace nameof {
|
||||
// tslint:disable-next-line no-unnecessary-generics
|
||||
function full<T>(func: (obj: T) => void, periodIndex?: number): string;
|
||||
function full(obj: any, periodIndex?: number): string;
|
||||
// tslint:disable-next-line no-unnecessary-generics
|
||||
function toArray<T>(func: (obj: T) => any[]): string[];
|
||||
function toArray(...args: any[]): string[];
|
||||
}
|
||||
|
||||
@@ -6,39 +6,49 @@ namespace TestNamespace {
|
||||
}
|
||||
|
||||
class TestClass {
|
||||
prop: string;
|
||||
prop1 = "";
|
||||
prop2 = "";
|
||||
}
|
||||
|
||||
// nameof tests
|
||||
nameof(TestClass); // $ExpectType string
|
||||
nameof<TestNamespace.TestType>(); // $ExpectType string
|
||||
nameof<TestClass>(t => t.prop); // $ExpectType string
|
||||
nameof<TestClass>(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<TestNamespace.TestType>(); // $ExpectType string
|
||||
nameof.full<TestNamespace.TestType>(1); // $ExpectType string
|
||||
nameof.full<TestClass>(t => t.prop); // $ExpectType string
|
||||
nameof.full<TestClass>(t => t.prop, 1); // $ExpectType string
|
||||
nameof.full<TestClass>(t => t.prop1); // $ExpectType string
|
||||
nameof.full<TestClass>(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<TestClass>(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[]
|
||||
|
||||
Reference in New Issue
Block a user