Skip to content

Instantly share code, notes, and snippets.

@kenfdev
Last active November 2, 2021 01:45
Show Gist options
  • Save kenfdev/75b77152c51ce02bbdc0570c55901192 to your computer and use it in GitHub Desktop.
Save kenfdev/75b77152c51ce02bbdc0570c55901192 to your computer and use it in GitHub Desktop.
JavaScript(TypeScript)
type Member = {
id: string;
firstName: string;
lastName: string;
age: number;
salary: number;
};
for (const field of ['firstName', 'lastName', 'age', 'salary'] as Array<
keyof Member
>) {
console.log(field);
}
// an example URI encoding when using the Instagram API
var apiUrl = 'https://api.instagram.com/v1/tags/';
apiUrl +=
encodeURIComponent('何かしらのタグ名') +
'/media/recent?client_id=' +
clientId;
export { default as MyModule } from 'src/MyModule';
export type NonFunctionPropertyNames<T> = {
[K in keyof T]: T[K] extends Function ? never : K;
}[keyof T];
export class Member {
static PUBLIC_FIELDS: NonFunctionPropertyNames<Member>[] = [
'id',
'avatar',
'firstName',
'lastName',
'department',
'joinedAt',
'phoneNumber',
'email',
'pr',
];
static PRIVATE_FIELDS: NonFunctionPropertyNames<Member>[] = ['age', 'salary'];
constructor(
public id: string,
public avatar: string,
public firstName: string,
public lastName: string,
public age: number,
public salary: number,
public department: Department,
public joinedAt: Date,
public phoneNumber: string,
public email: string,
public pr: string
) {}
}
// https://stackoverflow.com/a/53662389
export class AppError extends Error {
code: ErrorCode;
constructor(message: string, code: ErrorCode) {
super(message);
this.code = code;
}
}
export const ErrorCodes = {
USER_NOT_FOUND: 'user_not_found',
} as const;
type ErrorKey = keyof typeof ErrorCodes;
export type ErrorCode = typeof ErrorCodes[ErrorKey];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment