-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Incorrect "'value' is specified more than once, so this usage will be overwritten. ts(2783)" #38535
Comments
The build was failing due to the typescript version `3.9.2` has a bug microsoft/TypeScript#38535 We will use the version prevous `3.9.2` which is `3.8.3`
The build was failing due to the typescript version `3.9.2` has a bug microsoft/TypeScript#38535 We will use the version prevous `3.9.2` which is `3.8.3`
I noticed that this issue has 4.0 as milestone. |
Same problem with
Reverting typescript to |
I'm worried Reverting typescript to TypeScript Version: 3.9.2 Code const person = {
age: 25,
firstName: 'John',
lastName: 'Cook',
};
console.log(person);
//'age' is specified more than once, so this usage will be overwritten.(2783)
//input.ts(12, 5): This spread always overwrites this property.
const hoge = {
age: 20,
area: 'NY',
title: 'Sales Manager',
...person,
};
console.log(hoge);
//noProblem
const hogehoge = {
...person,
age: 20,
area: 'NY',
title: 'Sales Manager',
};
console.log(hogehoge);
|
@yamuun it's useless to write const hoge = {
age: 20,
area: 'NY',
title: 'Sales Manager',
...person,
}; cause age won't be 20 in hoge. The spread always overwrites age property. So, it's ok to see "This spread always overwrites this property". |
Should be fixed now |
@DanielRosenwasser |
I'm not sure what you want from me, but:
|
The issue is not resolved in 3.9.3 'addressNickName' is specified more than once, so this usage will be overwritten. const data: Address = {
addressNickName: "Home",
streetName: "12th Street",
...payload,
}; |
@yogeshkotadiya without knowing the type of |
I was hitting a bug in 3.9.2 with the breadcrumbs CL [1] that is fixed in 3.9.3 via this PR [2]. (I've verified locally that it is fixed). [1]: microsoft/TypeScript#38535 [2]: microsoft/TypeScript#38577 DISABLE_THIRD_PARTY_CHECK=typescript update Change-Id: Ia874e5936a5bbf0bf26f751ab746976f71910f25 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2218013 Commit-Queue: Jack Franklin <[email protected]> Auto-Submit: Jack Franklin <[email protected]> Reviewed-by: Tim van der Lippe <[email protected]>
I was hitting a bug in 3.9.2 with the breadcrumbs CL [1] that is fixed in 3.9.3 via this PR [2]. (I've verified locally that it is fixed). [1]: microsoft/TypeScript#38535 [2]: microsoft/TypeScript#38577 DISABLE_THIRD_PARTY_CHECK=typescript update Change-Id: Ia874e5936a5bbf0bf26f751ab746976f71910f25 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2218013 Commit-Queue: Jack Franklin <[email protected]> Auto-Submit: Jack Franklin <[email protected]> Reviewed-by: Tim van der Lippe <[email protected]>
@master117 You are spreading an array into an object spread there. That probably does not do what you want anyways. Or rather, realistically, your JS is fine: but the return type of your method is |
@phryneas Thanks for the fast reply. I made a typo, already fixed, the return is obviously Object not Object[]. The objects will be something like: But it seems that removing the [] has resolved the error. So Object works fine, but Object[] doesn't. My problem is solved :) I would have assumed something like [{key: value}, {key: value}] should work as well. Or rather throw a different type of error. As we then end with
|
Well, in this case the error was entirely accurate, as you were spreading an object with a defined |
Aaaah, of course, thank you again. |
Funny thing about all this is sometimes I deliberately put a redundant property in a list - from a readability standpoint so it's clear what the intent was. Or as a quick fix when I had bad data that didn't conform to the typescript interface. As others have said, can fix putting the |
Which has a different runtime behaviour and exactly what the error is warning about. |
Same problem with 3.9.6 |
I have the exact same error with the test code below (I tagged the failing line with a '<===' comment): it says
Where is generateVariants: (upsMock: UPSMock, appId: string, count: number, customAttrs?: Record<string, string>[]) => {
const VARIANT_NAME_PREFIX = 'TEST VARIANT';
const variants = [];
const genRandomVariantDef = () => {
if (Math.round(Math.random() * 10) % 2 === 0) {
// Android variant
return {
type: 'android',
googleKey: '123456',
projectNumber: '1234556',
} as AndroidVariant;
} else {
// iOS variant
return {
type: 'ios',
production: false,
certificate: '123',
} as IOSVariant;
}
};
for (let i = 0; i < count; i++) {
variants.push(
upsMock.getImpl().createVariant(appId, {
name: `${VARIANT_NAME_PREFIX} ${i}`, // <======. 'name' is specified more than once, so this usage will be overwritten.
developer: 'admin',
variantID: Guid.raw(),
...(customAttrs ? customAttrs[i] : genRandomVariantDef()),
} as Variant)
);
}
return variants;
} |
@ziccardi this looks legit. You should probably open a new Issue for that, as it is a different bug, even though it results in the same error message (this one has definitely been fixed). |
@phryneas nvm. I leave it here for the log: when I was trying to create a simple snippet to replicate the issue, I noticed it was compiling fine. So the solution jumped to my mind. The error resides in the export interface Variant {
id: string;
variantID: string;
name: string;
description: string;
developer: string;
secret: string;
type: VariantType;
metadata?: {
activity: number;
deviceCount: number;
};
} So, even if I don't really specify the |
I am using TS 3.9.6 and the issue still exist. see the simple code here:
Get error: |
@nisimjoseph The reason is that in the interface Config {
Version?:string;
publisher?:string;
} |
Thank you on the quick response. |
@nisimjoseph Yes, but the values you "get from the outside" are into an object that implements the |
@ziccardi I see your point, but this is not the case here. Just think I have 20 configurations properties and I know not each client will need all of them and will set them in runtime in JS. |
@nisimjoseph If the object you are receiving does not contains all the mandatory fields, then it is not a function send(config:Config) {
const finalConfig:Config = {
publisher: "name",
Version: "1.0",
...config as {},
}
} Anyway, this is not a bug: compiler is right. |
love the |
@ziccardi I notice when I am using the following it gives me also nested object errors, which is better (use interface Config {
Version:string;
publisher:string;
}
function send(config:Partial<Config>) {
const finalConfig:Config = {
publisher: "name",
Version: "1.0",
...config,
}
} And, I know the compiler is working fine, I was surprised it added in 3.8.x without a tsconfig way to disable it. |
@nisimjoseph this is working for me: interface Config {
Version:string;
publisher:string;
}
function send(config:Config) {
const finalConfig:Config = {
...config,
publisher: config.publisher || "name",
Version: config.Version || "1.0"
}
} |
thank you @Vladyslav-Apukhtin, it will work in this way but I can drop the use of |
The use of the spread opertor causes issues in TypeScript 3.9.x To avoid this issue we use Object.assign to return on object with default values. TypeScript error: error TS2783: '<XYZ>' is specified more than once, so this usage will be overwritten. See Travis build with errors: https://travis-ci.org/github/joule-labs/joule-extension/builds/713053315 Related TypeScript issues: microsoft/TypeScript#39671 microsoft/TypeScript#38535
|
Could we please stop posting unrelated stuff here? This issue has been fixed and everything after that is either worthy of a new ticket or not of interest any more, as this bug has been fixed. |
I agree 👆 |
TypeScript Version: 3.9.2
Search Terms:
Code
Expected behavior:
No error, as
value
inSelectProps
is optional andSelectProps
even defaults to an empty object.Actual behavior:
Playground Link:
none, as the playground does not seem to load the material-ui types
The text was updated successfully, but these errors were encountered: