|
| 1 | +=== tests/cases/compiler/test.ts === |
| 2 | +import {dropPrivateProps1, dropPrivateProps2} from './api'; |
| 3 | +>dropPrivateProps1 : Symbol(dropPrivateProps1, Decl(test.ts, 0, 8)) |
| 4 | +>dropPrivateProps2 : Symbol(dropPrivateProps2, Decl(test.ts, 0, 26)) |
| 5 | + |
| 6 | +const a = dropPrivateProps1({foo: 42, _bar: 'secret'}); // type is {foo: number} |
| 7 | +>a : Symbol(a, Decl(test.ts, 1, 5)) |
| 8 | +>dropPrivateProps1 : Symbol(dropPrivateProps1, Decl(test.ts, 0, 8)) |
| 9 | +>foo : Symbol(foo, Decl(test.ts, 1, 29)) |
| 10 | +>_bar : Symbol(_bar, Decl(test.ts, 1, 37)) |
| 11 | + |
| 12 | +//a._bar // error: _bar does not exist <===== as expected |
| 13 | +const b = dropPrivateProps2({foo: 42, _bar: 'secret'}); // type is {foo: number, _bar: string} |
| 14 | +>b : Symbol(b, Decl(test.ts, 3, 5)) |
| 15 | +>dropPrivateProps2 : Symbol(dropPrivateProps2, Decl(test.ts, 0, 26)) |
| 16 | +>foo : Symbol(foo, Decl(test.ts, 3, 29)) |
| 17 | +>_bar : Symbol(_bar, Decl(test.ts, 3, 37)) |
| 18 | + |
| 19 | +//b._bar // no error, type of b._bar is string <===== NOT expected |
| 20 | + |
| 21 | +=== tests/cases/compiler/api.ts === |
| 22 | +import {excludePrivateKeys1, excludePrivateKeys2} from './internal'; |
| 23 | +>excludePrivateKeys1 : Symbol(excludePrivateKeys1, Decl(api.ts, 0, 8)) |
| 24 | +>excludePrivateKeys2 : Symbol(excludePrivateKeys2, Decl(api.ts, 0, 28)) |
| 25 | + |
| 26 | +export const dropPrivateProps1 = <Obj>(obj: Obj) => excludePrivateKeys1(obj); |
| 27 | +>dropPrivateProps1 : Symbol(dropPrivateProps1, Decl(api.ts, 1, 12)) |
| 28 | +>Obj : Symbol(Obj, Decl(api.ts, 1, 34)) |
| 29 | +>obj : Symbol(obj, Decl(api.ts, 1, 39)) |
| 30 | +>Obj : Symbol(Obj, Decl(api.ts, 1, 34)) |
| 31 | +>excludePrivateKeys1 : Symbol(excludePrivateKeys1, Decl(api.ts, 0, 8)) |
| 32 | +>obj : Symbol(obj, Decl(api.ts, 1, 39)) |
| 33 | + |
| 34 | +export const dropPrivateProps2 = <Obj>(obj: Obj) => excludePrivateKeys2(obj); |
| 35 | +>dropPrivateProps2 : Symbol(dropPrivateProps2, Decl(api.ts, 2, 12)) |
| 36 | +>Obj : Symbol(Obj, Decl(api.ts, 2, 34)) |
| 37 | +>obj : Symbol(obj, Decl(api.ts, 2, 39)) |
| 38 | +>Obj : Symbol(Obj, Decl(api.ts, 2, 34)) |
| 39 | +>excludePrivateKeys2 : Symbol(excludePrivateKeys2, Decl(api.ts, 0, 28)) |
| 40 | +>obj : Symbol(obj, Decl(api.ts, 2, 39)) |
| 41 | + |
| 42 | +=== tests/cases/compiler/internal.ts === |
| 43 | +export declare function excludePrivateKeys1<Obj>(obj: Obj): {[K in PublicKeys1<keyof Obj>]: Obj[K]}; |
| 44 | +>excludePrivateKeys1 : Symbol(excludePrivateKeys1, Decl(internal.ts, 0, 0)) |
| 45 | +>Obj : Symbol(Obj, Decl(internal.ts, 0, 44)) |
| 46 | +>obj : Symbol(obj, Decl(internal.ts, 0, 49)) |
| 47 | +>Obj : Symbol(Obj, Decl(internal.ts, 0, 44)) |
| 48 | +>K : Symbol(K, Decl(internal.ts, 0, 62)) |
| 49 | +>PublicKeys1 : Symbol(PublicKeys1, Decl(internal.ts, 1, 100)) |
| 50 | +>Obj : Symbol(Obj, Decl(internal.ts, 0, 44)) |
| 51 | +>Obj : Symbol(Obj, Decl(internal.ts, 0, 44)) |
| 52 | +>K : Symbol(K, Decl(internal.ts, 0, 62)) |
| 53 | + |
| 54 | +export declare function excludePrivateKeys2<Obj>(obj: Obj): {[K in PublicKeys2<keyof Obj>]: Obj[K]}; |
| 55 | +>excludePrivateKeys2 : Symbol(excludePrivateKeys2, Decl(internal.ts, 0, 100)) |
| 56 | +>Obj : Symbol(Obj, Decl(internal.ts, 1, 44)) |
| 57 | +>obj : Symbol(obj, Decl(internal.ts, 1, 49)) |
| 58 | +>Obj : Symbol(Obj, Decl(internal.ts, 1, 44)) |
| 59 | +>K : Symbol(K, Decl(internal.ts, 1, 62)) |
| 60 | +>PublicKeys2 : Symbol(PublicKeys2, Decl(internal.ts, 2, 64)) |
| 61 | +>Obj : Symbol(Obj, Decl(internal.ts, 1, 44)) |
| 62 | +>Obj : Symbol(Obj, Decl(internal.ts, 1, 44)) |
| 63 | +>K : Symbol(K, Decl(internal.ts, 1, 62)) |
| 64 | + |
| 65 | +export type PublicKeys1<T> = T extends `_${string}` ? never : T; |
| 66 | +>PublicKeys1 : Symbol(PublicKeys1, Decl(internal.ts, 1, 100)) |
| 67 | +>T : Symbol(T, Decl(internal.ts, 2, 24)) |
| 68 | +>T : Symbol(T, Decl(internal.ts, 2, 24)) |
| 69 | +>T : Symbol(T, Decl(internal.ts, 2, 24)) |
| 70 | + |
| 71 | +type PublicKeys2<T> = T extends `_${string}` ? never : T; |
| 72 | +>PublicKeys2 : Symbol(PublicKeys2, Decl(internal.ts, 2, 64)) |
| 73 | +>T : Symbol(T, Decl(internal.ts, 3, 17)) |
| 74 | +>T : Symbol(T, Decl(internal.ts, 3, 17)) |
| 75 | +>T : Symbol(T, Decl(internal.ts, 3, 17)) |
| 76 | + |
0 commit comments