Skip to content

[Feature request] keyword final type for output full final type in .d.ts #31154

@bluelovers

Description

@bluelovers

Search Terms

Suggestion

with keyword final, output a final type typescript know in .d.ts

Use Cases

this help when we import a.ts will didn't need import other file for get type info

Examples

b.ts

export type A2 = {
	a: number,
}

export type B2 = {
	b: number,
}

origin

a.ts

import { A2, B2 } from './b'

type A1 = {
	a: number,
}

type B1 = {
	b: number,
}

export type C1 = A1 & B1
export type C2 = A2 & B2

=>

.d.ts

import { A2, B2 } from './b';
declare type A1 = {
    a: number;
};
declare type B1 = {
    b: number;
};
export declare type C1 = A1 & B1;
export declare type C2 = A2 & B2;

with keyword final

a.ts

import { A2, B2 } from './b'

export type A1 = {
	a: number,
}

export type B1 = {
	b: number,
}

export final type C1 = A1 & B1
export final type C2 = A2 & B2

=>

will no need to know what is A1 B1

and also will not import b.ts for know what is A2, B2 when import a.ts

export declare type C1 = {
	a: number,
	b: number,
}
export declare type C2 = {
	a: number,
	b: number,
}

or

export declare type C1 = {
	a: number,
} & {
	b: number,
}
export declare type C2 = {
	a: number,
} & {
	b: number,
}

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureDomain: Declaration EmitThe issue relates to the emission of d.ts filesSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions