Skip to content

Instantly share code, notes, and snippets.

View akihisa-shimada's full-sized avatar

akihisa-shimada

View GitHub Profile
import { Helmet, HelmetProvider } from "react-helmet-async";
const faqSchema = {
"@context": "https://schema.org",
"@type": "FAQPage",
mainEntity: [
{
"@type": "Question",
name: "よくある質問",
acceptedAnswer: {
function identity<T>(arg: T): T {
return arg;
}
console.log(identity<string>("string"));
console.log(identity(1));
interface Lengthwise {
length: number;
}
function loggingIdentity<T>(arg: T): T {
console.log(arg.length);
// -> Property 'length' does not exist on type 'T'.(2339)
return arg;
}
const fetcher = async(url: string): Promise<any> => {
const res = await fetch(url).then(res => res.json());
return res;
}
export const getUser = async(): Promise<any> => {
const user = await fetcher('https://example.com/api/user');
return user;
}
const fetcher = async<T>(url: string): Promise<T> => {
const res = await fetch(url).then<T>(res => res.json());
return res;
}
export const getUser = async(): Promise<{id: number, name: string}> => {
const user = await fetcher<{id: number, name: string}>('https://example.com/api/user');
return user;
}
const functionA = <T, U>(bool: boolean, param1: T, param2: U): T | U => {
if (bool) return param1;
return param2;
}
const result1 = functionA(true, 1, '文字列');
const result2 = functionA(false, 1, '文字列');
console.log(result1) // 1
console.log(result2) // 文字列
interface ExampleInterface<T, U> {
value1: T;
value2: U;
}
const obj: ExampleInterface<string, number> = { value1: '文字列', value2: 1 };
console.log(obj.value1); // 文字列
console.log(obj.value2); // 1
interface Lengthwise {
length: number;
}
function loggingIdentity<T extends Lengthwise>(arg: T): T {
console.log(arg.length);
return arg;
}
loggingIdentity(['hello world'])
package com.example.proto.grpc.exception.message;
import com.google.protobuf.Message;
import com.google.rpc.LocalizedMessage;
/**
* エラーメッセージの詳細を扱います
*/
public interface DetailMessage {
package com.example.proto.grpc.exception.message;
import io.grpc.Status;
/**
* 特定のgRPCレスポンスのための例外クラスです。
*
* @see org.springframework.web.server.ResponseStatusException
*/
public class ResponseStatusException extends RuntimeException {