-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Types: Update ScriptableContext (#8556)
* Types: Update ScriptableContext * Add data array type test
- Loading branch information
Showing
4 changed files
with
54 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
import { Scriptable } from '../index.esm'; | ||
import { ChartType, Scriptable, ScriptableContext } from '../index.esm'; | ||
|
||
interface test { | ||
pie?: Scriptable<number, 'pie'>, | ||
line?: Scriptable<number, 'line'>, | ||
testA?: Scriptable<number, 'pie' | 'line' | 'bar'> | ||
testB?: Scriptable<number, 'pie' | 'line' | 'bar'> | ||
testC?: Scriptable<number, 'pie' | 'line' | 'bar'> | ||
pie?: Scriptable<number, ScriptableContext<'pie'>>, | ||
line?: Scriptable<number, ScriptableContext<'line'>>, | ||
testA?: Scriptable<number, ScriptableContext<'pie'>> | ||
testB?: Scriptable<number, ScriptableContext<'line' | 'bar'>> | ||
testC?: Scriptable<number, ScriptableContext<'pie' | 'line' | 'bar'>> | ||
testD?: Scriptable<number, ScriptableContext<ChartType>> | ||
} | ||
|
||
const pieScriptable: Scriptable<number, 'pie'> = (ctx) => ctx.parsed; | ||
const lineScriptable: Scriptable<number, 'line'> = (ctx) => ctx.parsed.x + ctx.parsed.y; | ||
|
||
export const testImpl: test = { | ||
pie: (ctx) => ctx.parsed, | ||
line: (ctx) => ctx.parsed.x + ctx.parsed.y, | ||
testA: pieScriptable, | ||
testB: lineScriptable, | ||
// @FIXME ts-expect-error combined type should not be any | ||
testC: (ctx) => ctx.fail | ||
testA: (ctx) => ctx.parsed, | ||
testB: (ctx) => ctx.parsed.x + ctx.parsed.y, | ||
// @ts-expect-error combined type should not be any | ||
testC: (ctx) => ctx.fail, | ||
// combined types are intersections and permit invalid usage | ||
testD: (ctx) => ctx.parsed + ctx.parsed.x + ctx.parsed.r + ctx.parsed._custom.barEnd | ||
}; | ||
|
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