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
2 changes: 1 addition & 1 deletion internal/checker/pseudotypenodebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (b *NodeBuilderImpl) pseudoTypeToNode(t *pseudochecker.PseudoType) *ast.Nod
// something a true syntactic ID emitter couldn't possibly know (since the signature could
// be from across files). This can't *really* happen in any cases ID doesn't already error on, though.
// Just something to keep in mind if the ID checker keeps growing.
isConst := b.ch.isConstContext(elements[0].Name)
isConst := b.ch.isConstContext(elements[0].Name.Parent.Parent)
newElements := make([]*ast.Node, 0, len(elements))

for _, e := range elements {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ export const obj1 = {

//// [declarationEmitConstObjectLiteralGenericMethod1.d.ts]
export declare const obj1: {
id<T>(value: T): T;
pair<T_1>(left: T_1, right: T_1): T_1[];
readonly id: <T>(value: T) => T;
readonly pair: <T_1>(left: T_1, right: T_1) => T_1[];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//// [tests/cases/compiler/declarationEmitReadonlyAsConst.ts] ////

//// [declarationEmitReadonlyAsConst.ts]
export const value = {
method(): string {
return "a";
},
prop: {
nested: 1,
},
} as const;


//// [declarationEmitReadonlyAsConst.js]
export const value = {
method() {
return "a";
},
prop: {
nested: 1,
},
};


//// [declarationEmitReadonlyAsConst.d.ts]
export declare const value: {
readonly method: () => string;
readonly prop: {
readonly nested: 1;
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [tests/cases/compiler/declarationEmitReadonlyAsConst.ts] ////

=== declarationEmitReadonlyAsConst.ts ===
export const value = {
>value : Symbol(value, Decl(declarationEmitReadonlyAsConst.ts, 0, 12))

method(): string {
>method : Symbol(method, Decl(declarationEmitReadonlyAsConst.ts, 0, 22))

return "a";
},
prop: {
>prop : Symbol(prop, Decl(declarationEmitReadonlyAsConst.ts, 3, 4))

nested: 1,
>nested : Symbol(nested, Decl(declarationEmitReadonlyAsConst.ts, 4, 9))

},
} as const;
>const : Symbol(const)

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//// [tests/cases/compiler/declarationEmitReadonlyAsConst.ts] ////

=== declarationEmitReadonlyAsConst.ts ===
export const value = {
>value : { readonly method: () => string; readonly prop: { readonly nested: 1; }; }
>{ method(): string { return "a"; }, prop: { nested: 1, },} as const : { readonly method: () => string; readonly prop: { readonly nested: 1; }; }
>{ method(): string { return "a"; }, prop: { nested: 1, },} : { readonly method: () => string; readonly prop: { readonly nested: 1; }; }

method(): string {
>method : () => string

return "a";
>"a" : "a"

},
prop: {
>prop : { readonly nested: 1; }
>{ nested: 1, } : { readonly nested: 1; }

nested: 1,
>nested : 1
>1 : 1

},
} as const;

11 changes: 11 additions & 0 deletions testdata/tests/cases/compiler/declarationEmitReadonlyAsConst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @strict: true
// @declaration: true

export const value = {
method(): string {
return "a";
},
prop: {
nested: 1,
},
} as const;
Loading