microsoft / microsoft/TypeScript

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

Open
#31,154 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Domain: Declaration Emit Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

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.

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 by comparing the a.ts and b.ts examples with the requested .d.ts output and clarify the intended semantics of the proposed final type. There are no repository files or tests named in the issue; done would require an agreed design and corresponding compiler behavior for the shown cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.