ts-auto-guard icon indicating copy to clipboard operation
ts-auto-guard copied to clipboard

Type aliases produce type guards with TS errors (TS6133)

Open doblinger-extron opened this issue 1 year ago • 1 comments

In my project, I'm making use of type aliases for primitives like string and number. This results in the following TS compilation error:

'{name}' is declared but its value is never read. ts(6133).

Reproduce Steps:

Create two type aliases:

// type1.ts
export type Type1 = string;

// type2.ts
export type Type2 = string;

Output:

import { Type1 } from "./type-1";

export function isType1(obj: unknown): obj is Type1 {
  const typedObj = obj as Type1;
  return typeof typedObj === "string";
}

// This import is not used, resulting in the ts6133 error
import { isType1 } from "./type-1.type-guard"; 
import { Type2 } from "./type-2";

export function isType2(obj: unknown): obj is Type2 {
  const typedObj = obj as Type2;
  return typeof typedObj === "string";
}

doblinger-extron avatar Sep 20 '23 13:09 doblinger-extron

Looks related to #189. Open to a PR for this, but I won't be able to fix it myself.

Are you able to disable that unused check on just guard files?

rhys-vdw avatar Oct 03 '23 10:10 rhys-vdw