programming language, superset of JavaScript that compiles to JavaScript

TypeScript (TS) is a high-level programming language that adds static typing with optional type annotations to JavaScript. It is designed for developing large applications. It transpiles to JavaScript. It is developed by … Wikipedia
Factsheet
Family ECMAScript
Designed by Microsoft,
Anders Hejlsberg,
Luke Hoban
Factsheet
Family ECMAScript
Designed by Microsoft,
Anders Hejlsberg,
Luke Hoban
🌐
TypeScript
typescriptlang.org β€Ί download
TypeScript: How to set up TypeScript
Then you use a dependency manager like npm, yarn or pnpm to download TypeScript into your project. ... All of these dependency managers support lockfiles, ensuring that everyone on your team is using the same version of the language. You can then run the TypeScript compiler using one of the ...
🌐
Yarn
classic.yarnpkg.com β€Ί en β€Ί package β€Ί typescript
Yarn
For Yarn 2+ docs and migration guide, see yarnpkg.com.
🌐
Plain English
plainenglish.io β€Ί blog β€Ί getting-started-with-yarn-3-and-typescript-125e7b537e6c
Getting Started with Yarn 3 and TypeScript
To get started you'll want to import the TypeScript plugin for Yarn, and install TypeScript itself of course, along with getting the environment setup using @yarnpkg/sdks we learned about earlier.
🌐
Medium
medium.com β€Ί @tharindugimras β€Ί typescript-setup-with-nodejs-yarn-package-manager-nodemon-fa9fb2275655
Typescript setup with Nodejs + Yarn Package manager + Nodemon | by Tharindu Gimras | Medium
March 3, 2023 - In this project, you can see that I’m using yarn as my package manager. To initialize the configuration file for the yarn package manager, let’s run these commands in your terminal/command line at typescript_with_node/ path.
🌐
WebDevAssist
webdevassist.com β€Ί typescript β€Ί typescript-installation
How to install TypeScript
This is the easiest way to install typescript. If you have installed any package manager like npm, yarn or pnpm, you can install typescript with just one line:
Top answer
1 of 2
1

As my comment mentions in the original question, from the yarn documentation:

TypeScript uses its own resolver as well. In this case the situation is a bit more complex - the TS team has some concerns about allowing third-party hooks inside the tsc compiler, meaning that we can’t work with it at the moment. That being said, TypeScript isn’t only tsc and as such we’ve been able to add PnP support to the popular ts-loader - meaning that as long as you compile your TypeScript through Webpack, everything works well! Consult the dedicated section about it for more information.

To enable yarn package resolution when using Typescript you have to use webpack with ts-loader. This is how I resolved it.

  • install the neccessary dependencies:

npm install webpack webpack-cli pnp-webpack-plugin ts-loader

  • Create a 'webpack.config.js' file in your project root directory with the following content:
const path = require('path');
const PnpWebpackPlugin = require('pnp-webpack-plugin');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');

const commonConfig = {
  mode: 'development',
  devtool: 'source-map',
  plugins: [
    new NodePolyfillPlugin(),
  ],
  output: {
    filename: '[name].js',
    path: path.resolve(__dirname, 'dist'),
  },
  node: {
    __dirname: false,
  },
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
    ],
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.js'],
    plugins: [PnpWebpackPlugin],
  },
  resolveLoader: {
    plugins: [PnpWebpackPlugin.moduleLoader(module)],
  },
};

module.exports = [
  Object.assign(
    {
      target: 'electron-main',
      entry: { main: './src/main.ts' },
    },
    commonConfig
  ),
  Object.assign(
    {
      target: 'electron-renderer',
      entry: { preload: './src/preload.ts' },
    },
    commonConfig
  ),
];
  • I updated my package.json with scripts to run webpack:
{
  "name": "ElectroMega",
  "packageManager": "[email protected]",
  "private": true,
  "scripts": {
    "build": "webpack",
    "prestart": "yarn run build",
    "start": "electron ./dist/main.js"
  },
  "devDependencies": {
    "html-webpack-plugin": "^5.3.2",
    "node-polyfill-webpack-plugin": "^1.1.4",
    "pnp-webpack-plugin": "^1.7.0",
    "ts-loader": "^9.2.6",
    "typescript": "^4.4.3",
    "webpack": "^5.54.0",
    "webpack-cli": "^4.8.0"
  },
  "dependencies": {
    "@tsconfig/node14": "^1.0.1",
    "@types/node": "^16.9.6",
    "electron": "^14.0.1"
  }
}
  • Then you should be able to build your code with the command:

yarn build

My solution was a result of following the webpack GettingStarted section that explained much of the troubles I had, and the basics of using webpack.

2 of 2
0

FWIW, iamkneel's answer from above worked for my. Had an express app that I was using Typescript for and set it up with yarn. Setting nodeLinker: node-modules in the .yarnrc.yml file took care of the compile issue.

🌐
Yarn
yarnpkg.com β€Ί package
Yarn
Yarn guarantees that installs that work today will keep working the same way in the future.
Find elsewhere
🌐
Medium
losikov.medium.com β€Ί part-1-project-initial-setup-typescript-node-js-31ba3aa7fbf1
Part 1. Project initial setup: TypeScript + Node.js | by Alex Losikov | Medium
November 3, 2020 - Install initial dependencies (-D flag is a development dependency): $ yarn add @types/node typescript $ yarn add -D ts-node
🌐
GitHub
gist.github.com β€Ί jbsulli β€Ί 881cb2e5d5d9c4e5e5d8736755c11ffb
Typescript Yarn 3 Plug'n'Play zero-install monorepo for VSCode Β· GitHub
Note: it's important that you have typescript installed at the root so that this step installs typescript sdk to .yarn/sdks/typescript. This is what VSCode will use to handle the Plug'n'Play (PnP) modules. Otherwise, you'll get a lot of Cannot find type definition file for ...
🌐
Medium
medium.com β€Ί swlh β€Ί getting-started-with-yarn-2-and-typescript-43321a3acdee
Getting started with Yarn 2 and TypeScript | by Sinclair | The Startup | Medium
October 26, 2021 - ➀ YN0000: β”” Completed in 0.22s ➀ YN0000: β”Œ Link step ➀ YN0000: β”” Completed ➀ YN0000: Done in 0.54s PS C:\…> yarn plugin import typescript ➀ YN0000: Downloading https://.../plugin-typescript.js ➀ YN0000: Saving the new plugin in .yarn/plugins/@yarnpkg/plugin-typescript.cjs ➀ YN0000: Done in 0.67sDid I mention Yarn Modern is fast? This just installs typescript, of course, but also adds the TypeScript plugin!
🌐
Yarn
yarnpkg.com β€Ί editor sdks
Editor SDKs | Yarn
(let ((project-directory (car (dir-locals-find-file default-directory)))) (setq lsp-clients-typescript-server-args `("--tsserver-path" ,(concat project-directory ".yarn/sdks/typescript/bin/tsserver") "--stdio"))))))) ... TypeScript support should then work out of the box with nvim-lspconfig and theia-ide/typescript-language-server. Install the ZipFS extension, which is maintained by the Yarn team.
🌐
Yarn
yarnpkg.com β€Ί overview
@yarnpkg/plugin-typescript | API | Yarn
❯ yarn/packages/plugin-typescript ❯ yarn add lodash ➀ YN0000: ·
🌐
Create React App
create-react-app.dev β€Ί docs β€Ί adding-typescript
Adding TypeScript | Create React App
npx create-react-app my-app --template typescript Copy ... If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app or yarn global ...
🌐
GitHub
github.com β€Ί yarnpkg β€Ί yarn β€Ί issues β€Ί 4226
Installing Typescript definitions for react and react-addons-test-utils is inconsistent with npm Β· Issue #4226 Β· yarnpkg/yarn
August 22, 2017 - Installing Typescript definitions for react and react-addons-test-utils is inconsistent with npm#4226 ... What is the current behavior? Performing a yarn add of @types/react@^15.6.1 and @types/react-addons-test-utils creates output that is inconsistent with npm install of the same packages.
Published Β  Aug 22, 2017
🌐
Medium
blog.ramosly.com β€Ί macbooks-typescript-zsh-oh-my-203b822ef5e6
MacBooks, Typescript, ZSH, Oh my! | by Joel Ramos | ramosly | blog
May 24, 2020 - I had installed typescript in the ... with yarn globally. Sure enough, after running brew install typescript I am now able to run tsc from anywhere. And this makes sense since brew manages all the files and symlinks for the things that it installs. I generally just think of brew as the package manager for Mac OS things, ...
🌐
TypeScript Execute
tsx.is β€Ί getting-started
Getting started | tsx
In your command-line, simply pass in a TypeScript file you'd like to run. It's that simple! ... To install tsx as a project development dependency, run the following command in your project directory: ... Project commands are usually organized ...