Last active
November 2, 2021 01:45
-
-
Save kenfdev/75b77152c51ce02bbdc0570c55901192 to your computer and use it in GitHub Desktop.
JavaScript(TypeScript)
This file contains hidden or 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 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); | |
} |
This file contains hidden or 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
// an example URI encoding when using the Instagram API | |
var apiUrl = 'https://api.instagram.com/v1/tags/'; | |
apiUrl += | |
encodeURIComponent('何かしらのタグ名') + | |
'/media/recent?client_id=' + | |
clientId; |
This file contains hidden or 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
export { default as MyModule } from 'src/MyModule'; |
This file contains hidden or 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
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 | |
) {} | |
} |
This file contains hidden or 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
// 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