TypeStrong / TypeStrong/ts-loader

webpack 5 + Vue + TS-Loader how to use generics?

Open
#1,620 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.5k
Forks
439
Avg merge
17h 17m
Merged PRs (30d)
2

Description

I tried to use generics with webpack and while I have no problems in my current Vite project I have no clue how to make it working with webpack.

I always receive TS2304: Cannot find name 'T'.
For example

<script setup lang="ts" generic="T extends string">
interface Props {
  modelValue: T;
}
const props = defineProps<Props>();
</script>

<template>{{ modelValue }}</template>

Is there a way to enable generics with this TS Loader and webpack 5? I created a minimal repo here
https://codesandbox.io/p/sandbox/webpack-vue-3-forked-p67wfr?welcome=true

Expected Behaviour
  • Vue generics should work
Actual Behaviour
  • Vue generics won't work -> see error above
Steps to Reproduce the Problem
  • create a Vue component and try to use generics with webpack
Location of a Minimal Repository that Demonstrates the Issue.

https://codesandbox.io/p/sandbox/webpack-vue-3-forked-p67wfr?welcome=true

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox minimal repository and reproduce the TS2304 error using the shown Vue component and webpack 5 setup. Trace how ts-loader processes the component's generic script syntax and determine whether the issue is configuration or unsupported handling; done means the repository's expected generic usage works or the limitation is clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, webpack
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.