-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(transformer): do not fail when accessing index of extended this f…
…or a computed property
- Loading branch information
Showing
4 changed files
with
67 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { createMock } from 'ts-auto-mock'; | ||
import { getLogsByCreateMockFileName, UnsupportedTypeLog } from '../utils/log'; | ||
import { OtherInterface } from './indexedAccess.warning.type'; | ||
|
||
describe('IndexedAccess Warning', () => { | ||
it('should log unsupported warning and assign null for `this` in extended interface with computed property name', async () => { | ||
const mock: OtherInterface = createMock<OtherInterface>(); | ||
|
||
expect(mock.prop<'[]'>()).toBeNull(); | ||
|
||
const logs: UnsupportedTypeLog[] = await getLogsByCreateMockFileName( | ||
'indexedAccess.warning.test.ts' | ||
); | ||
expect(logs.length).toBe(1); | ||
|
||
expect(logs[0].header).toContain( | ||
'WARNING: Transformer - IndexedAccessType transformation failed: cannot find property [] of - this[K]' | ||
); | ||
expect(logs[0].created).toMatch( | ||
/created file:\/\/.*indexedAccess\.warning\.test\.ts:[0-9]*:[0-9]*/ | ||
); | ||
expect(logs[0].usedBy).toMatch( | ||
/used by file:\/\/.*indexedAccess\.warning\.type\.ts:[0-9]*:[0-9]*/ | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface OtherInterface extends StandardInterface { | ||
'[]': string; | ||
} | ||
|
||
export interface StandardInterface { | ||
prop<K extends keyof this>(): this[K]; | ||
} |