Skip to content

Instantly share code, notes, and snippets.

Avatar
🐶
Working from home

aiya000 aiya000

🐶
Working from home
View GitHub Profile
View .eslintrc.js
module.exports = {
env: {
browser: true,
es6: true,
node: true,
},
extends: ['plugin:import/errors', 'plugin:import/warnings', 'plugin:import/typescript'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
View Test.ts
const chars = [
'亜',
'哀',
'挨',
'愛',
'曖',
'悪',
'握',
'圧',
'扱',
View Test.sh
#!/bin/bash
negative_state=$(cat <<- END
{
"state": "failure",
"context": "poi",
"description": "hi"
}
END
)
echo "$negative_state"
View prettier.config.js
module.exports = {
trailingComma: 'all',
tabWidth: 2,
semi: false,
singleQuote: true,
printWidth: 100,
}
View .eslintrc.js
module.exports = {
root: true,
env: {
browser: true,
node: true,
},
extends: [
'@nuxtjs/eslint-config-typescript',
'@vue/prettier',
'@vue/prettier/@typescript-eslint',
View Test.ts
const x: { x: number } | null = { x: 10 }
console.log(x.x) // no errors
const y: { x: number } | null = null
console.log(y.x) // 2531: Object is possibly 'null'.
View Test.ts
/**
* The type 'true' means a proof is satisfied.
* The type 'never' means a proof is not satisfied.
*/
// Basic of this idea.
type AWrongProof = { x: number } extends { x: string } ? true : never
// Compile NG
@aiya000
aiya000 / types.ts
Created Feb 20, 2021
TypeScriptは`interface Foo { ... }`と`type Foo = { ... }`を区別するっぽい!?
View types.ts
/**
* Proves that A and B is the same types.
*/
export type Equal<A, B> = A extends B ? (B extends A ? true : never) : never
/**
* Makes all fields of A to `<its-type> | null`.
*/
export type Nullable<A extends Record<string, unknown>> = { [K in keyof A]: A[K] | null }
@aiya000
aiya000 / Nullable.ts
Created Feb 20, 2021
証明できてる?
View Nullable.ts
/**
* Proves that A and B is the same types.
*/
export type Equal<A, B> = A extends B ? (B extends A ? true : never) : never
/**
* Makes all fields of A to `<its-type> | null`.
*/
export type Nullable<A extends Record<string, unknown>> = { [K in keyof A]: A[K] | null }
@aiya000
aiya000 / auth-user.ts
Last active Feb 19, 2021
Getting an access token of VRChat API. and then getting friend list using it. VRChat APIでアクセストークンを使って、フレンドを取得するやつ。
View auth-user.ts
import axios from 'axios'
function isThatArray<T>(x: unknown, p: (a: unknown) => a is T): x is Array<T> {
return Array.isArray(x) && x.every(p)
}
function isString(x: unknown): x is string {
return typeof x === 'string'
}