DEV Community

Yasunori Tanaka
Yasunori Tanaka

Posted on • Updated on

[From April 23 to 29] The things I knew and thought last week

[Typescript] What is the difference between d.ts and ts. Should I write an interface except for implementation?

A .d.ts is defined for js file that does not exist type definition. We cannot write implementation in a .d.ts file.

[Tslint] disable unused importing error

We set this Eslint rule before we change.

eslint.json

'@typescript-eslint/no-unused-vars': 'error',

This rule prevents us from productivity. We then changed this setting to "warn," and Webpack can build an app even imported variable is not used.

But this setting is not right generally. So I set this as "error" when testing an app in CI.

eslint.json

'@typescript-eslint/no-unused-vars': 'warn',

Finally, we could get more productivity in development and keep clean code in production.

[Golang] Get own function name for logging

I wanted to log an error message with the function name a caller called, and I referred to this.

Go 1.7 added some runtime functions to improve accessing stack frame information.

From the Go 1.7 Release Notes:

The new function CallersFrames translates a PC slice obtained from Callers into a sequence of frames corresponding to the call stack. This new API should be preferred instead of direct use…

In my case, I can get a function name in this way.

func getFuncName() string {
  pc := make([]uintptr, 15)
  n := runtime.Callers(2, pc) // get caller's function name
  frames := runtime.CallersFrames(pc[:n])
  frame, _ := frames.Next()
  return frame.Function
}

[Vue] Managing common APIs within some util class

Now, I'm thinking.

DB Migration early developments use not a binary format. After settling down development, use a binary format.

I used MySQL Workbench in our team first. In the first month, we started our project, we changed(add, delete, and update) DB tables pretty often and we should change MySQL Workbench file sequentially because the file was binary data, we could not solve conflict with Git. Therefore, we came to the conclusion that in a development phase, we should use a text format DDL file, and after finish that, we can use a binary format DB management tool if we want because it will be less changing DDL.

[Golang] change table name with TableName() in GORM

https://gorm.io/docs/conventions.html#Pluralized-Table-Name

I can change a table name arbitrarily with TableName().

[JavaScript] throw exception

throw new Error('Error!')

Same of other langs.

Top comments (0)