Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Jan 22, 2025
1 parent b352c0f commit 230925a
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/baselines/reference/selfCallGenericJsDoc1.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
index.js(13,42): error TS2345: Argument of type 'Children<T>' is not assignable to parameter of type 'any[]'.
Type '{ children: Children<T>[] | undefined; }' is missing the following properties from type 'any[]': length, pop, push, concat, and 16 more.


==== index.js (1 errors) ====
/**
* @template T
* @typedef {T & { children: Children<T>[] | undefined }} Children
*/

/**
* @template T
* @param {Children<T>[]} groups item and groups
*/
export const spaceLimited = (groups) => {
for (let i = 0; i < groups.length; i++) {
const group = groups[i];
spaceLimited(/** @type {Children<T>} */(group.children)); // should error
~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type 'Children<T>' is not assignable to parameter of type 'any[]'.
!!! error TS2345: Type '{ children: Children<T>[] | undefined; }' is missing the following properties from type 'any[]': length, pop, push, concat, and 16 more.
}
};

37 changes: 37 additions & 0 deletions tests/baselines/reference/selfCallGenericJsDoc1.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//// [tests/cases/compiler/selfCallGenericJsDoc1.ts] ////

=== index.js ===
/**
* @template T
* @typedef {T & { children: Children<T>[] | undefined }} Children
*/

/**
* @template T
* @param {Children<T>[]} groups item and groups
*/
export const spaceLimited = (groups) => {
>spaceLimited : Symbol(spaceLimited, Decl(index.js, 9, 12))
>groups : Symbol(groups, Decl(index.js, 9, 29))

for (let i = 0; i < groups.length; i++) {
>i : Symbol(i, Decl(index.js, 10, 9))
>i : Symbol(i, Decl(index.js, 10, 9))
>groups.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
>groups : Symbol(groups, Decl(index.js, 9, 29))
>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --))
>i : Symbol(i, Decl(index.js, 10, 9))

const group = groups[i];
>group : Symbol(group, Decl(index.js, 11, 7))
>groups : Symbol(groups, Decl(index.js, 9, 29))
>i : Symbol(i, Decl(index.js, 10, 9))

spaceLimited(/** @type {Children<T>} */(group.children)); // should error
>spaceLimited : Symbol(spaceLimited, Decl(index.js, 9, 12))
>group.children : Symbol(children, Decl(index.js, 2, 18))
>group : Symbol(group, Decl(index.js, 11, 7))
>children : Symbol(children, Decl(index.js, 2, 18))
}
};

66 changes: 66 additions & 0 deletions tests/baselines/reference/selfCallGenericJsDoc1.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//// [tests/cases/compiler/selfCallGenericJsDoc1.ts] ////

=== index.js ===
/**
* @template T
* @typedef {T & { children: Children<T>[] | undefined }} Children
*/

/**
* @template T
* @param {Children<T>[]} groups item and groups
*/
export const spaceLimited = (groups) => {
>spaceLimited : <T>(groups: Children<T>[]) => void
> : ^ ^^ ^^ ^^^^^^^^^
>(groups) => { for (let i = 0; i < groups.length; i++) { const group = groups[i]; spaceLimited(/** @type {Children<T>} */(group.children)); // should error }} : <T>(groups: Children<T>[]) => void
> : ^ ^^ ^^ ^^^^^^^^^
>groups : Children<T>[]
> : ^^^^^^^^^^^^^

for (let i = 0; i < groups.length; i++) {
>i : number
> : ^^^^^^
>0 : 0
> : ^
>i < groups.length : boolean
> : ^^^^^^^
>i : number
> : ^^^^^^
>groups.length : number
> : ^^^^^^
>groups : Children<T>[]
> : ^^^^^^^^^^^^^
>length : number
> : ^^^^^^
>i++ : number
> : ^^^^^^
>i : number
> : ^^^^^^

const group = groups[i];
>group : Children<T>
> : ^^^^^^^^^^^
>groups[i] : Children<T>
> : ^^^^^^^^^^^
>groups : Children<T>[]
> : ^^^^^^^^^^^^^
>i : number
> : ^^^^^^

spaceLimited(/** @type {Children<T>} */(group.children)); // should error
>spaceLimited(/** @type {Children<T>} */(group.children)) : void
> : ^^^^
>spaceLimited : <T>(groups: Children<T>[]) => void
> : ^ ^^ ^^ ^^^^^^^^^
>(group.children) : Children<T>
> : ^^^^^^^^^^^
>group.children : Children<T>[] | undefined
> : ^^^^^^^^^^^^^^^^^^^^^^^^^
>group : Children<T>
> : ^^^^^^^^^^^
>children : Children<T>[] | undefined
> : ^^^^^^^^^^^^^^^^^^^^^^^^^
}
};

22 changes: 22 additions & 0 deletions tests/cases/compiler/selfCallGenericJsDoc1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// @strict: true
// @noEmit: true
// @checkJs: true
// @allowJs: true

// @filename: index.js

/**
* @template T
* @typedef {T & { children: Children<T>[] | undefined }} Children
*/

/**
* @template T
* @param {Children<T>[]} groups item and groups
*/
export const spaceLimited = (groups) => {
for (let i = 0; i < groups.length; i++) {
const group = groups[i];
spaceLimited(/** @type {Children<T>} */(group.children)); // should error
}
};

0 comments on commit 230925a

Please sign in to comment.