-
Notifications
You must be signed in to change notification settings - Fork 12.8k
[ID-Prep] PR4 - Preserve types nodes from type assertions in declaration emit #57589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
dragomirtitian
wants to merge
7
commits into
microsoft:main
from
bloomberg:ts-verbatim-declrations-from-assertions
Closed
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
297ba1b
Added tests for using type from assertion in declarations.
dragomirtitian 9399b32
Allow extraction of type from type assertions for declaration emit
dragomirtitian 4f63418
Accessor declared type was not visited
dragomirtitian c84eeb0
Merge remote-tracking branch 'remotes/origin/main' into ts-verbatim-d…
dragomirtitian 3833bf5
Incorporated feedback
dragomirtitian 5506934
Infer type from assertion for export assignment.
dragomirtitian 83c3715
Added test for JS assertions (not affected)
dragomirtitian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,5 @@ var x = {}; | |
//// [duplicatePropertiesInTypeAssertions02.d.ts] | ||
declare let x: { | ||
a: number; | ||
a: number; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
tests/baselines/reference/hugeDeclarationOutputGetsTruncatedWithError.types
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
258 changes: 258 additions & 0 deletions
258
tests/baselines/reference/verbatim-declarations-assertions(strict=false).js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,258 @@ | ||
//// [tests/cases/compiler/verbatim-declarations-assertions.ts] //// | ||
|
||
//// [assertToTypeReferences.ts] | ||
type P = { } & { name: string } | ||
|
||
export let vLet = null! as P | ||
export const vConst = null! as P | ||
|
||
export function fn(p = null! as P) {} | ||
|
||
export function fnWithRequiredDefaultParam(p = null! as P, req: number) {} | ||
|
||
export class C { | ||
field = null! as P | ||
readonly roFiled = null! as P; | ||
method(p = null! as P) {} | ||
methodWithRequiredDefault(p = null! as P, req: number) {} | ||
methodWithRequiredDefault2(p = null! as P, req: number) {} | ||
|
||
constructor(public ctorField = null! as P) {} | ||
} | ||
|
||
export default null! as P; | ||
|
||
//// [assertToTypeLiteral.ts] | ||
export let vLet = null! as {} & { name: string } | ||
export const vConst = null! as {} & { name: string } | ||
|
||
export function fn(p = null! as {} & { name: string }) {} | ||
|
||
export function fnWithRequiredDefaultParam(p = null! as {} & { name: string }, req: number) {} | ||
|
||
export class C { | ||
field = null! as {} & { name: string } | ||
readonly roFiled = null! as {} & { name: string }; | ||
method(p = null! as {} & { name: string }) {} | ||
methodWithRequiredDefault(p = null! as {} & { name: string }, req: number) {} | ||
|
||
constructor(public ctorField = null! as {} & { name: string }) {} | ||
|
||
get x() { return null! as {} & { name: string } } | ||
set x(v) { } | ||
} | ||
|
||
export default null! as {} & { name: string } | ||
|
||
|
||
//// [assertToOtherTypes.ts] | ||
export const vNumberLiteral = null! as 1 | 1 | ||
export const vStringLiteral = null! as "1" | "1" | ||
export const vLiteral = null! as "1" | "1" | ||
|
||
type R = { foo: string } | ||
|
||
export class C { | ||
// under !strictNullChecks all types can be reused from the assertion | ||
// under strictNullChecks we need to add undefined, and we can't always know we can | ||
// Can't know if references contain undefined, fall back to inference | ||
tsResolve? = null! as R | R; | ||
tsResolve2? = null! as R | R | string; | ||
// Simple type. we can add undefined | ||
reuseType? = null! as ((p: R) => void) | string | string; | ||
reuseType2? = null! as (new (p: R) => R) | string | string; | ||
reuseType3? = null! as string | number | bigint | symbol | unknown | any | never | symbol; | ||
reuseType4? = null! as [R, R, R] | [R, R, R]; | ||
reuseType5? = null! as R[] | R[]; | ||
reuseType6? = null! as 1 | "2" | 1n | 1n; | ||
reuseType7? = null! as `A` | `A`; | ||
reuseType8? = null! as `${string}-ok` | `${string}-ok`; | ||
reuseType9? = null! as this | this; | ||
} | ||
|
||
//// [assertToTypeReferences.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.C = exports.fnWithRequiredDefaultParam = exports.fn = exports.vConst = exports.vLet = void 0; | ||
exports.vLet = null; | ||
exports.vConst = null; | ||
function fn(p) { | ||
if (p === void 0) { p = null; } | ||
} | ||
exports.fn = fn; | ||
function fnWithRequiredDefaultParam(p, req) { | ||
if (p === void 0) { p = null; } | ||
} | ||
exports.fnWithRequiredDefaultParam = fnWithRequiredDefaultParam; | ||
var C = /** @class */ (function () { | ||
function C(ctorField) { | ||
if (ctorField === void 0) { ctorField = null; } | ||
this.ctorField = ctorField; | ||
this.field = null; | ||
this.roFiled = null; | ||
} | ||
C.prototype.method = function (p) { | ||
if (p === void 0) { p = null; } | ||
}; | ||
C.prototype.methodWithRequiredDefault = function (p, req) { | ||
if (p === void 0) { p = null; } | ||
}; | ||
C.prototype.methodWithRequiredDefault2 = function (p, req) { | ||
if (p === void 0) { p = null; } | ||
}; | ||
return C; | ||
}()); | ||
exports.C = C; | ||
exports.default = null; | ||
//// [assertToTypeLiteral.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.C = exports.fnWithRequiredDefaultParam = exports.fn = exports.vConst = exports.vLet = void 0; | ||
exports.vLet = null; | ||
exports.vConst = null; | ||
function fn(p) { | ||
if (p === void 0) { p = null; } | ||
} | ||
exports.fn = fn; | ||
function fnWithRequiredDefaultParam(p, req) { | ||
if (p === void 0) { p = null; } | ||
} | ||
exports.fnWithRequiredDefaultParam = fnWithRequiredDefaultParam; | ||
var C = /** @class */ (function () { | ||
function C(ctorField) { | ||
if (ctorField === void 0) { ctorField = null; } | ||
this.ctorField = ctorField; | ||
this.field = null; | ||
this.roFiled = null; | ||
} | ||
C.prototype.method = function (p) { | ||
if (p === void 0) { p = null; } | ||
}; | ||
C.prototype.methodWithRequiredDefault = function (p, req) { | ||
if (p === void 0) { p = null; } | ||
}; | ||
Object.defineProperty(C.prototype, "x", { | ||
get: function () { return null; }, | ||
set: function (v) { }, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return C; | ||
}()); | ||
exports.C = C; | ||
exports.default = null; | ||
//// [assertToOtherTypes.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.C = exports.vLiteral = exports.vStringLiteral = exports.vNumberLiteral = void 0; | ||
exports.vNumberLiteral = null; | ||
exports.vStringLiteral = null; | ||
exports.vLiteral = null; | ||
var C = /** @class */ (function () { | ||
function C() { | ||
// under !strictNullChecks all types can be reused from the assertion | ||
// under strictNullChecks we need to add undefined, and we can't always know we can | ||
// Can't know if references contain undefined, fall back to inference | ||
this.tsResolve = null; | ||
this.tsResolve2 = null; | ||
// Simple type. we can add undefined | ||
this.reuseType = null; | ||
this.reuseType2 = null; | ||
this.reuseType3 = null; | ||
this.reuseType4 = null; | ||
this.reuseType5 = null; | ||
this.reuseType6 = null; | ||
this.reuseType7 = null; | ||
this.reuseType8 = null; | ||
this.reuseType9 = null; | ||
} | ||
return C; | ||
}()); | ||
exports.C = C; | ||
|
||
|
||
//// [assertToTypeReferences.d.ts] | ||
type P = {} & { | ||
name: string; | ||
}; | ||
export declare let vLet: P; | ||
export declare const vConst: P; | ||
export declare function fn(p?: P): void; | ||
export declare function fnWithRequiredDefaultParam(p: P, req: number): void; | ||
export declare class C { | ||
ctorField: P; | ||
field: P; | ||
readonly roFiled: P; | ||
method(p?: P): void; | ||
methodWithRequiredDefault(p: P, req: number): void; | ||
methodWithRequiredDefault2(p: P, req: number): void; | ||
constructor(ctorField?: P); | ||
} | ||
declare const _default: { | ||
name: string; | ||
}; | ||
export default _default; | ||
//// [assertToTypeLiteral.d.ts] | ||
export declare let vLet: {} & { | ||
name: string; | ||
}; | ||
export declare const vConst: {} & { | ||
name: string; | ||
}; | ||
export declare function fn(p?: {} & { | ||
name: string; | ||
}): void; | ||
export declare function fnWithRequiredDefaultParam(p: {} & { | ||
name: string; | ||
}, req: number): void; | ||
export declare class C { | ||
ctorField: {} & { | ||
name: string; | ||
}; | ||
field: {} & { | ||
name: string; | ||
}; | ||
readonly roFiled: {} & { | ||
name: string; | ||
}; | ||
method(p?: {} & { | ||
name: string; | ||
}): void; | ||
methodWithRequiredDefault(p: {} & { | ||
name: string; | ||
}, req: number): void; | ||
constructor(ctorField?: {} & { | ||
name: string; | ||
}); | ||
get x(): { | ||
name: string; | ||
}; | ||
set x(v: { | ||
name: string; | ||
}); | ||
} | ||
declare const _default: { | ||
name: string; | ||
}; | ||
export default _default; | ||
//// [assertToOtherTypes.d.ts] | ||
export declare const vNumberLiteral: 1 | 1; | ||
export declare const vStringLiteral: "1" | "1"; | ||
export declare const vLiteral: "1" | "1"; | ||
type R = { | ||
foo: string; | ||
}; | ||
export declare class C { | ||
tsResolve?: R | R; | ||
tsResolve2?: R | R | string; | ||
reuseType?: ((p: R) => void) | string | string; | ||
reuseType2?: (new (p: R) => R) | string | string; | ||
reuseType3?: string | number | bigint | symbol | unknown | any | never | symbol; | ||
reuseType4?: [R, R, R] | [R, R, R]; | ||
reuseType5?: R[] | R[]; | ||
reuseType6?: 1 | "2" | 1n | 1n; | ||
reuseType7?: `A` | `A`; | ||
reuseType8?: `${string}-ok` | `${string}-ok`; | ||
reuseType9?: this | this; | ||
} | ||
export {}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.