microsoft / microsoft/TypeScript

emit code miss return type in .d.ts ( 3.9.0-dev.20200408 )

Open
#37,840 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs Investigation
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: Version 3.9.0-dev.20200408

Search Terms:

Code

export declare const lifecycleMap: {
	install: {
		readonly name: "install";
		readonly before: readonly ["preinstall"];
		readonly after: readonly ["postinstall", "prepublish", "prepare", "preshrinkwrap", "shrinkwrap", "postshrinkwrap"];
	};
	pack: {
		readonly name: "pack";
		readonly ignoreSelf: true;
		readonly before: readonly ["prepublish", "prepare", "prepack"];
		readonly after: readonly ["postpack"];
	};
	publish: {
		readonly name: "publish";
		readonly before: readonly ["prepublish", "prepare", "prepublishOnly", "prepack", "postpack"];
		readonly after: readonly ["postpublish"];
	};
};

export interface ILifecycleEntry
{
	readonly name: string;
	readonly ignoreSelf?: boolean;
	readonly before: readonly string[];
	readonly after: readonly string[];
}

export type ILifecycleMapKeys = keyof typeof lifecycleMap;

export type ILifecycleMap<K extends string = string> = typeof lifecycleMap & Record<K, ILifecycleEntry>;


export function getLifecycleCore<K extends ILifecycleMapKeys>(scriptName: string | K)
{
	if (isKnownLifecycleKey(scriptName))
	{
		return lifecycleMap[scriptName]
	}

	return (lifecycleMap as ILifecycleMap)[scriptName]
}

export function getLifecycle<K extends string | ILifecycleMapKeys>(scriptName: K)
{
	return getLifecycleCore(scriptName) ?? {
		name: scriptName,
		before: [
			`pre${scriptName}`
		],
		after: [
			`post${scriptName}`
		],
	}
}

export function isKnownLifecycleKey<K extends ILifecycleMapKeys>(scriptName: string | K): scriptName is ILifecycleMapKeys
{
	return scriptName in lifecycleMap
}

tsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es2019",
        "jsx": "preserve",
        "moduleResolution": "node",
        "allowJs": false,
        "allowUmdGlobalAccess": false,
        "sourceMap": true,
        "inlineSourceMap": false,
        "inlineSources": true,
        "declaration": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "allowSyntheticDefaultImports": true,
        "resolveJsonModule": true,
        "strict": false,
        "strictBindCallApply": true,
        "strictNullChecks": false,
        "strictFunctionTypes": true,
        "noImplicitThis": true,
        "preserveConstEnums": true,
        "forceConsistentCasingInFileNames": true,
        "incremental": true,
        "noErrorTruncation": true,
        "locale": "zh-TW",
        "removeComments": false,
        "traceResolution": false,
        "newLine": "lf",
        "esModuleInterop": true
    },

Expected behavior:

same as Playground
https://www.typescriptlang.org/v2/en/play?target=6&module=1&ts=3.9.0-beta#code/KYDwDg9gTgLgBAE2AYwDYEMrDsiA7AZ3lQEsAzFATzWAFl0wAuOAbwCgBIEwmdVVZuw4cs6BPlSU4edAFtgzAETcifVIoDcnEcDESpAI2BloCuKPF5JcANqKwWFb36KAuluEX9cdGRjAoZi8rKTtIIic1RQAaOHssMABXA1ICAAsYuIdgMExgTPjgdKhuAGsAdygGAuKyyurY+wgiWrwKqrA3DwBfD1zkUsFtYOsZeSV+0s1h3UtrEgBzPFMAZWBUMmYYKETgDx09ELgjEywg2e8whOTUjMbs3KwCh-QBrpnD619-QPMLo7CzRgk3eHF6nCSKRI6SGnn+ozkZnsN2hGX2I0MxlM50+oUKkNuzwSeSJORR6QA8iFSSD7kCQe4PnMpN8AjjmbYmkQCajQeDwWxQJBYHBuD8yK9sABJAAy5CoNAAonhtpQ2EIMdJEcwiCU8AsPJrFsssGsNgB+ZgGCAQVC6PCG+GY05mTW67gLGyMg4c1m-N3bD1erTdNiC8DQeAwShgaVyijIah2+hgADSwEoBDgAF44KUMxAyHBo7HC3BSAmk3QGFpw8KozG4-LEzQUwAeVNwUD+PAILPu-U5uADhYAPiHJeAZYrCuTDDgADI4AAlFDQBAd2Ky5tV5Wq0e1uuRuBkRJ4ZAwEj4OALYAweOz4AAYVMHa7IB7fbg28rrYY6czUcAAoCGQEowBgAA5bVh0DQcAB84FTABKdVOHIOAgOhVNlnKPAHxbO0AJAsCSAg6D5GQ1COCEHQYESKA8HLHc-zAGxQPAqDEVcThQ04LB6MYzCZ0I6swB8LMf0fFNkPY0jyO4tg+KFY9T3PS9r1ve8WLtN9u2AXt+zghY4EQqTRJTACCGAjiyK48YkNQjU7wYpitIIqsXywEjOIo4BkLgc1zVYbQxjMWyFPkaJtBObFbG0DgAANsgAEhYCL7OAbpEu0VxouEP1mBsBLkqBNKMr87Lcvy0NlIjEU1IvK8mOw3D8J04AAL0j8DK-cyq0sjNrJ8uy-J1YzTMcnV5My0VJI81irLQujXOHGa-NFJiRIGhglLYIA
tsc Version 3.9.0-dev.20200408
node v13.12.0

export declare function getLifecycle<K extends string | ILifecycleMapKeys>(scriptName: K): {
    readonly name: "install";
    readonly before: readonly ["preinstall"];
    readonly after: readonly ["postinstall", "prepublish", "prepare", "preshrinkwrap", "shrinkwrap", "postshrinkwrap"];
} | {
    readonly name: "pack";
    readonly ignoreSelf: true;
    readonly before: readonly ["prepublish", "prepare", "prepack"];
    readonly after: readonly ["postpack"];
} | {
    readonly name: "publish";
    readonly before: readonly ["prepublish", "prepare", "prepublishOnly", "prepack", "postpack"];
    readonly after: readonly ["postpublish"];
} | ILifecycleEntry;

Actual behavior:

export declare function getLifecycle<K extends string | ILifecycleMapKeys>(scriptName: K): {
    readonly name: "install";
    readonly before: readonly ["preinstall"];
    readonly after: readonly ["postinstall", "prepublish", "prepare", "preshrinkwrap", "shrinkwrap", "postshrinkwrap"];
} | {
    readonly name: "publish";
    readonly before: readonly ["prepublish", "prepare", "prepublishOnly", "prepack", "postpack"];
    readonly after: readonly ["postpublish"];
} | ILifecycleEntry;
  export declare function getLifecycle<K extends string | ILifecycleMapKeys>(scriptName: K): {
      readonly name: "install";
      readonly before: readonly ["preinstall"];
      readonly after: readonly ["postinstall", "prepublish", "prepare", "preshrinkwrap", "shrinkwrap", "postshrinkwrap"];
  } | {
-     readonly name: "pack";
-     readonly ignoreSelf: true;
-     readonly before: readonly ["prepublish", "prepare", "prepack"];
-     readonly after: readonly ["postpack"];
- } | {
      readonly name: "publish";
      readonly before: readonly ["prepublish", "prepare", "prepublishOnly", "prepack", "postpack"];
      readonly after: readonly ["postpublish"];
  } | ILifecycleEntry;

Playground Link:

Related Issues:

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

Run the supplied TypeScript 3.9.0-dev.20200408 example with the provided tsconfig.json and compare its generated .d.ts with the Playground's expected output. Trace declaration emit for the inferred getLifecycle return type; done when the generated declaration retains the pack variant and matches the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.