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
// marker interface for module | |
interface Module { | |
_module_: 1 | |
} | |
type ValueOf<T> = T[keyof T]; | |
type PropPaths< | |
T, | |
K1 extends string = never, | |
K2 extends string = never, |
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
/* Code formatter | |
* Based on prettier, and add support for Vue SFC | |
* For vue SFC, format only in <script> and <style>. | |
* | |
* Required dependencies | |
* - prettier | |
* - glob | |
* - chalk | |
*/ | |
const prettier = require("prettier"); |
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
// Example usage: | |
// node ./run-prettier.js "./**/*.{json,js,ts,vue}" | |
// | |
const prettier = require("prettier"); | |
const glob = require("glob").sync; | |
const fs = require("fs"); | |
const chalk = require("chalk"); | |
/* RegExp to capture whole tag of script/style | |
* |
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
import Vue, { VNode, VNodeChildrenArrayContents } from "vue"; | |
import { VueConstructor } from "vue/types/vue"; | |
export function vueWith<T>(): VueConstructor<Vue & T> { | |
return Vue as any; | |
} | |
export const TestComponent = vueWith<{ | |
$refs: { test: HTMLDivElement }, | |
$scopedSlots: { |
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
type DiffKey<T extends string, U extends string> = ( | |
& {[P in T]: P } | |
& {[P in U]: never } | |
& { [x: string]: never } | |
)[T]; | |
type Omit<T, K extends keyof T> = Pick<T, DiffKey<keyof T, K>>; | |
type Diff<T, U> = Omit<T, keyof U & keyof T>; |
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
import Vue from "vue"; | |
declare type Class<T> = new (...args: any[]) => T; | |
declare type EventHandlers<E> = { | |
[K in keyof E]?: (payload: E[K]) => void; | |
} | |
declare type ComponentOptions<Props> = Vue.ComponentOptions<Vue> & { | |
props: PropsDefinition<keyof Props> | |
}; |
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
/* | |
* 1. ../tsconfig.json に設定ファイルを置く | |
* 2. ../cases/ の中に example.ts みたいなファイルを置く (/// TSXXXX: ~ でその行で期待するコンパイルを記述する。~の部分は正規表現) | |
* 3. _runner.ts を ava で実行すると、出力サンプルみたいな感じで結果が出力される | |
*/ | |
import * as ts from "typescript/lib/typescript"; | |
import * as fs from "fs"; | |
import * as path from "path"; | |
import * as glob from "glob"; |
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
// MIT License | |
import * as Vuex from "vuex"; | |
/* | |
* Infrastructure types | |
*/ | |
export type KV<K extends string, V> = { [_ in K]: V }; | |
export type Payload<T, V> = { type: T } & V; | |
/* |
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
interface Context { prop1: string; } | |
type Handlers<T> = { | |
[K in keyof T]: (ctx: Context, payload: T[K]) => void | |
}; | |
function test<T>(handlers: Handlers<T>): Partial<T> { | |
return {} as any; | |
} | |
const t = test({ | |
foo(ctx, payload: number) { |
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
import * as Vue from "vue"; | |
import * as assert from "power-assert"; | |
function nextTick() { | |
return new Promise((resolve, _) => Vue.nextTick(resolve)); | |
} | |
describe("vue component tests", function() { | |
it("works properly", async function() { // don't use `done` with async function | |
const vm = new Vue({ ... }); |