Skip to content
tinytip

Latest tips / 15

Restart TypeScript server in VS Code with a command

June 14, 2021
#vscode

Sometimes the TypeScript server in Visual Studio Code crashes which results in broken auto completion. You can restart the server with a single command.

Make sure that you have a TypeScript file open, press Ctrl+Shift+P (or Cmd+Shift+P on macOS) to open the Command Palette and type restart, then select the command "TypeScript: Restart TS server".

Restart TS server command in VS Code

The status bar at the bottom of the window will show the status of the server.

Copy text in the browser console with the copy() function

June 14, 2021
#devtools #console

The DevTools provide a global copy() function. Use that function in the Console tab to copy any content into your clipboard.

// Copy some static text into the clipboard
copy("hello world");

// Copy the page title
copy(document.title);

// Copy some content from localStorage
copy(localStorage.getItem("test"));

Find elements in the browser console with $$

June 14, 2021
#devtools #console

Use $$(...) in the Console tab of the DevTools to query elements. It's a quick way for using querySelectorAll.

// Find all "a" elements
$$("a");

// Find all div elements with "container" in the class attribute
$$("div[class*='container']");

Use $0 in the browser console to get the current element

June 14, 2021
#devtools #console

When you select an element in the Elements tab of the Browser DevTools you can use $0 in the Console tab to refer to that element.

// Logs the selected element of the Elements tab
$0;

// Access any property or method on that element
$0.href;

Get the current text color with currentColor in CSS

June 14, 2021
#css #color

In CSS the special variable currentColor gives you access to the current text color of the element. You can use this value in other properties like border-color to automatically adjust the border to match the text color.

.button {
border: 1px solid currentColor; /* border color is blue */
color: blue;
}

.button:hover {
/* border color automatically changes to darkblue */
color: darkblue;
}