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
|
=== tests/cases/compiler/test.ts ===
import {dropPrivateProps1, dropPrivateProps2} from './api';
>dropPrivateProps1 : <Obj>(obj: Obj) => { [K in import("tests/cases/compiler/internal").PublicKeys1<keyof Obj>]: Obj[K]; }
>dropPrivateProps2 : <Obj>(obj: Obj) => { [K in keyof Obj extends `_${string}` ? never : keyof Obj]: Obj[K]; }
const a = dropPrivateProps1({foo: 42, _bar: 'secret'}); // type is {foo: number}
>a : { foo: number; }
>dropPrivateProps1({foo: 42, _bar: 'secret'}) : { foo: number; }
>dropPrivateProps1 : <Obj>(obj: Obj) => { [K in import("tests/cases/compiler/internal").PublicKeys1<keyof Obj>]: Obj[K]; }
>{foo: 42, _bar: 'secret'} : { foo: number; _bar: string; }
>foo : number
>42 : 42
>_bar : string
>'secret' : "secret"
//a._bar // error: _bar does not exist <===== as expected
const b = dropPrivateProps2({foo: 42, _bar: 'secret'}); // type is {foo: number, _bar: string}
>b : { foo: number; }
>dropPrivateProps2({foo: 42, _bar: 'secret'}) : { foo: number; }
>dropPrivateProps2 : <Obj>(obj: Obj) => { [K in keyof Obj extends `_${string}` ? never : keyof Obj]: Obj[K]; }
>{foo: 42, _bar: 'secret'} : { foo: number; _bar: string; }
>foo : number
>42 : 42
>_bar : string
>'secret' : "secret"
//b._bar // no error, type of b._bar is string <===== NOT expected
=== tests/cases/compiler/api.ts ===
import {excludePrivateKeys1, excludePrivateKeys2} from './internal';
>excludePrivateKeys1 : <Obj>(obj: Obj) => { [K in import("tests/cases/compiler/internal").PublicKeys1<keyof Obj>]: Obj[K]; }
>excludePrivateKeys2 : <Obj>(obj: Obj) => { [K in keyof Obj extends `_${string}` ? never : keyof Obj]: Obj[K]; }
export const dropPrivateProps1 = <Obj>(obj: Obj) => excludePrivateKeys1(obj);
>dropPrivateProps1 : <Obj>(obj: Obj) => { [K in import("tests/cases/compiler/internal").PublicKeys1<keyof Obj>]: Obj[K]; }
><Obj>(obj: Obj) => excludePrivateKeys1(obj) : <Obj>(obj: Obj) => { [K in import("tests/cases/compiler/internal").PublicKeys1<keyof Obj>]: Obj[K]; }
>obj : Obj
>excludePrivateKeys1(obj) : { [K in import("tests/cases/compiler/internal").PublicKeys1<keyof Obj>]: Obj[K]; }
>excludePrivateKeys1 : <Obj>(obj: Obj) => { [K in import("tests/cases/compiler/internal").PublicKeys1<keyof Obj>]: Obj[K]; }
>obj : Obj
export const dropPrivateProps2 = <Obj>(obj: Obj) => excludePrivateKeys2(obj);
>dropPrivateProps2 : <Obj>(obj: Obj) => { [K in keyof Obj extends `_${string}` ? never : keyof Obj]: Obj[K]; }
><Obj>(obj: Obj) => excludePrivateKeys2(obj) : <Obj>(obj: Obj) => { [K in keyof Obj extends `_${string}` ? never : keyof Obj]: Obj[K]; }
>obj : Obj
>excludePrivateKeys2(obj) : { [K in keyof Obj extends `_${string}` ? never : keyof Obj]: Obj[K]; }
>excludePrivateKeys2 : <Obj>(obj: Obj) => { [K in keyof Obj extends `_${string}` ? never : keyof Obj]: Obj[K]; }
>obj : Obj
=== tests/cases/compiler/internal.ts ===
export declare function excludePrivateKeys1<Obj>(obj: Obj): {[K in PublicKeys1<keyof Obj>]: Obj[K]};
>excludePrivateKeys1 : <Obj>(obj: Obj) => { [K in PublicKeys1<keyof Obj>]: Obj[K]; }
>obj : Obj
export declare function excludePrivateKeys2<Obj>(obj: Obj): {[K in PublicKeys2<keyof Obj>]: Obj[K]};
>excludePrivateKeys2 : <Obj>(obj: Obj) => { [K in PublicKeys2<keyof Obj>]: Obj[K]; }
>obj : Obj
export type PublicKeys1<T> = T extends `_${string}` ? never : T;
>PublicKeys1 : PublicKeys1<T>
type PublicKeys2<T> = T extends `_${string}` ? never : T;
>PublicKeys2 : PublicKeys2<T>
|