Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//// [tests/cases/compiler/declarationEmitDefaultTypeParams.ts] ////

//// [declarationEmitDefaultTypeParams.ts]
export interface Effect<A, E = never, R = never> {
readonly _A: A
readonly _E: E
readonly _R: R
}

export interface Deferred<A, E = never> {
readonly _A: A
readonly _E: E
}

// When return type uses defaults, they should be omitted
export const succeed = <A>(value: A): Effect<A> => ({ _A: value, _E: undefined as never, _R: undefined as never })
export const fail = <E>(error: E): Effect<never, E> => ({ _A: undefined as never, _E: error, _R: undefined as never })
export const makeDeferred = <A>(): Deferred<A> => ({ _A: undefined as never, _E: undefined as never })

// Many default params - only non-defaults should appear
export interface Channel<Out, Err = never, Done = void, In = unknown, InErr = unknown, InDone = unknown, Env = never> {
readonly _Out: Out
}

export const fromString = (s: string): Channel<string> => ({ _Out: s })


//// [declarationEmitDefaultTypeParams.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromString = exports.makeDeferred = exports.fail = exports.succeed = void 0;
// When return type uses defaults, they should be omitted
const succeed = (value) => ({ _A: value, _E: undefined, _R: undefined });
exports.succeed = succeed;
const fail = (error) => ({ _A: undefined, _E: error, _R: undefined });
exports.fail = fail;
const makeDeferred = () => ({ _A: undefined, _E: undefined })
// Many default params - only non-defaults should appear
;
exports.makeDeferred = makeDeferred;
const fromString = (s) => ({ _Out: s });
exports.fromString = fromString;


//// [declarationEmitDefaultTypeParams.d.ts]
export interface Effect<A, E = never, R = never> {
readonly _A: A;
readonly _E: E;
readonly _R: R;
}
export interface Deferred<A, E = never> {
readonly _A: A;
readonly _E: E;
}
export declare const succeed: <A>(value: A) => Effect<A>;
export declare const fail: <E>(error: E) => Effect<never, E>;
export declare const makeDeferred: <A>() => Deferred<A>;
export interface Channel<Out, Err = never, Done = void, In = unknown, InErr = unknown, InDone = unknown, Env = never> {
readonly _Out: Out;
}
export declare const fromString: (s: string) => Channel<string>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//// [tests/cases/compiler/declarationEmitIndexedAccessPreservation.ts] ////

//// [declarationEmitIndexedAccessPreservation.ts]
export interface Transaction {
readonly Service: {
retry: boolean
readonly journal: Map<unknown, { readonly version: number; value: unknown }>
}
}

export interface Config {
readonly Options: {
readonly timeout: number
readonly retries: number
}
}

// Indexed access should be preserved in declaration emit
export const withTransaction = <A>(
f: (state: Transaction["Service"]) => A
): A => f({ retry: false, journal: new Map() })

export const getOptions = (): Config["Options"] => ({ timeout: 1000, retries: 3 })

// Nested indexed access
export interface Nested {
readonly Level1: {
readonly Level2: {
readonly value: string
}
}
}

export const getDeep = (): Nested["Level1"]["Level2"] => ({ value: "test" })


//// [declarationEmitIndexedAccessPreservation.js]
// Indexed access should be preserved in declaration emit
export const withTransaction = (f) => f({ retry: false, journal: new Map() });
export const getOptions = () => ({ timeout: 1000, retries: 3 });
export const getDeep = () => ({ value: "test" });


//// [declarationEmitIndexedAccessPreservation.d.ts]
export interface Transaction {
readonly Service: {
retry: boolean;
readonly journal: Map<unknown, {
readonly version: number;
value: unknown;
}>;
};
}
export interface Config {
readonly Options: {
readonly timeout: number;
readonly retries: number;
};
}
export declare const withTransaction: <A>(f: (state: Transaction["Service"]) => A) => A;
export declare const getOptions: () => Config["Options"];
export interface Nested {
readonly Level1: {
readonly Level2: {
readonly value: string;
};
};
}
export declare const getDeep: () => Nested["Level1"]["Level2"];
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//// [tests/cases/compiler/declarationEmitIteratorTypeParams.ts] ////

//// [declarationEmitIteratorTypeParams.ts]
// Iterator with two type params should not get third param
export const fromIterator = <A, L>(
iterator: () => Iterator<A, L>
): Array<A> => {
const result: Array<A> = []
let next = iterator().next()
while (!next.done) {
result.push(next.value as A)
next = iterator().next()
}
return result
}

// Generator function
export function* counted(): Generator<number, string> {
yield 1
yield 2
yield 3
return "done"
}

// Iterable with return type
export const fromIterable = <A, L>(iterable: Iterable<A, L>): Array<A> => Array.from(iterable as Iterable<A>)

// AsyncIterator
export const fromAsyncIterator = <A, L>(
iterator: () => AsyncIterator<A, L>
): Promise<Array<A>> => Promise.resolve([])


//// [declarationEmitIteratorTypeParams.js]
// Iterator with two type params should not get third param
export const fromIterator = (iterator) => {
const result = [];
let next = iterator().next();
while (!next.done) {
result.push(next.value);
next = iterator().next();
}
return result;
};
// Generator function
export function* counted() {
yield 1;
yield 2;
yield 3;
return "done";
}
// Iterable with return type
export const fromIterable = (iterable) => Array.from(iterable);
// AsyncIterator
export const fromAsyncIterator = (iterator) => Promise.resolve([]);


//// [declarationEmitIteratorTypeParams.d.ts]
export declare const fromIterator: <A, L>(iterator: () => Iterator<A, L>) => Array<A>;
export declare function counted(): Generator<number, string>;
export declare const fromIterable: <A, L>(iterable: Iterable<A, L>) => Array<A>;
export declare const fromAsyncIterator: <A, L>(iterator: () => AsyncIterator<A, L>) => Promise<Array<A>>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//// [tests/cases/compiler/declarationEmitNamespaceTypePreservation.ts] ////

//// [declarationEmitNamespaceTypePreservation.ts]
export namespace Pull {
export interface Halt<E> {
readonly _tag: "Halt"
readonly error: E
}

export type ExcludeHalt<E> = Exclude<E, Halt<unknown>>
}

export namespace Arr {
export type NonEmptyReadonlyArray<A> = readonly [A, ...ReadonlyArray<A>]
}

// Namespace-qualified types should be preserved
export const excludeHalt = <E>(error: E): Pull.ExcludeHalt<E> => error as Pull.ExcludeHalt<E>
export const toNonEmpty = <A>(arr: Arr.NonEmptyReadonlyArray<A>): Arr.NonEmptyReadonlyArray<A> => arr
export const process = <E>(input: E): Pull.ExcludeHalt<E> | null => input as Pull.ExcludeHalt<E>


//// [declarationEmitNamespaceTypePreservation.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.process = exports.toNonEmpty = exports.excludeHalt = void 0;
// Namespace-qualified types should be preserved
const excludeHalt = (error) => error;
exports.excludeHalt = excludeHalt;
const toNonEmpty = (arr) => arr;
exports.toNonEmpty = toNonEmpty;
const process = (input) => input;
exports.process = process;


//// [declarationEmitNamespaceTypePreservation.d.ts]
export declare namespace Pull {
interface Halt<E> {
readonly _tag: "Halt";
readonly error: E;
}
type ExcludeHalt<E> = Exclude<E, Halt<unknown>>;
}
export declare namespace Arr {
type NonEmptyReadonlyArray<A> = readonly [A, ...ReadonlyArray<A>];
}
export declare const excludeHalt: <E>(error: E) => Pull.ExcludeHalt<E>;
export declare const toNonEmpty: <A>(arr: Arr.NonEmptyReadonlyArray<A>) => Arr.NonEmptyReadonlyArray<A>;
export declare const process: <E>(input: E) => Pull.ExcludeHalt<E> | null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//// [tests/cases/compiler/declarationEmitOptionalObjects.ts] ////

//// [declarationEmitOptionalObjects.ts]
interface Options {
readonly timeout?: number
readonly retries?: number
}

// Named interface optional param
export const configure = (options?: Options): void => { console.log(options) }

// Inline object type optional param
export const fetchData = (options?: { timeout: number }): void => { console.log(options) }

// Complex inline object with optional properties
export const createQueue = (options?: {
readonly strategy?: "sliding" | "dropping" | "suspend"
}): void => { console.log(options) }

// Return type with optional
export const getConfig = (): Options | undefined => undefined

// Optional in generic position
export const withDefault = <T>(value: T, defaultValue?: T): T => value ?? defaultValue!


//// [declarationEmitOptionalObjects.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.withDefault = exports.getConfig = exports.createQueue = exports.fetchData = exports.configure = void 0;
// Named interface optional param
const configure = (options) => { console.log(options); }
// Inline object type optional param
;
exports.configure = configure;
// Inline object type optional param
const fetchData = (options) => { console.log(options); }
// Complex inline object with optional properties
;
exports.fetchData = fetchData;
// Complex inline object with optional properties
const createQueue = (options) => { console.log(options); }
// Return type with optional
;
exports.createQueue = createQueue;
// Return type with optional
const getConfig = () => undefined
// Optional in generic position
;
exports.getConfig = getConfig;
// Optional in generic position
const withDefault = (value, defaultValue) => value !== null && value !== void 0 ? value : defaultValue;
exports.withDefault = withDefault;


//// [declarationEmitOptionalObjects.d.ts]
interface Options {
readonly timeout?: number;
readonly retries?: number;
}
export declare const configure: (options?: Options) => void;
export declare const fetchData: (options?: {
timeout: number;
}) => void;
export declare const createQueue: (options?: {
readonly strategy?: "sliding" | "dropping" | "suspend";
}) => void;
export declare const getConfig: () => Options | undefined;
export declare const withDefault: <T>(value: T, defaultValue?: T) => T;
export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//// [tests/cases/compiler/declarationEmitOptionalParams.ts] ////

//// [declarationEmitOptionalParams.ts]
// Simple optional string
export const count = (label?: string): void => { console.log(label) }

// Optional object parameter
export const fetch = (url: string, options?: { timeout: number }): void => { console.log(url, options) }

// Multiple optional params
export const multi = (a?: string, b?: number): void => { console.log(a, b) }

// Optional with union type
export const unionOptional = (value?: string | number): void => { console.log(value) }

// Rest params after optional
export const withRest = (label?: string, ...args: Array<unknown>): void => { console.log(label, args) }


//// [declarationEmitOptionalParams.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.withRest = exports.unionOptional = exports.multi = exports.fetch = exports.count = void 0;
// Simple optional string
const count = (label) => { console.log(label); }
// Optional object parameter
;
exports.count = count;
// Optional object parameter
const fetch = (url, options) => { console.log(url, options); }
// Multiple optional params
;
exports.fetch = fetch;
// Multiple optional params
const multi = (a, b) => { console.log(a, b); }
// Optional with union type
;
exports.multi = multi;
// Optional with union type
const unionOptional = (value) => { console.log(value); }
// Rest params after optional
;
exports.unionOptional = unionOptional;
// Rest params after optional
const withRest = (label, ...args) => { console.log(label, args); };
exports.withRest = withRest;


//// [declarationEmitOptionalParams.d.ts]
export declare const count: (label?: string) => void;
export declare const fetch: (url: string, options?: {
timeout: number;
}) => void;
export declare const multi: (a?: string, b?: number) => void;
export declare const unionOptional: (value?: string | number) => void;
export declare const withRest: (label?: string, ...args: Array<unknown>) => void;
Loading
Loading